BCC302 – Python Programming
Brief & Precise Solutions (Question-wise)
SECTION A
Q1(a) Python variables store data values. Example:
x = 10 (int), y = 3.5 (float)
Q1(b) for-loop uses range with fixed iterations; while-loop runs until condition becomes false.
Q1(c) String slicing extracts part of string. Example: s='Python'; s[0:3]='Pyt'
Q1(d) Tuple is immutable sequence (), list is mutable [].
Q1(e) Dictionary stores key-value pairs. Example: d={'a':1}; d['b']=2
Q1(f) read() reads entire file; readline() reads one line at a time.
Q1(g) Encapsulation binds data and methods using classes and access control.
SECTION B
Q2(a) Operators: arithmetic, relational, logical. Data types: int, float, str.
Program:
if n%2==0: print('Even') else: print('Odd')
Q2(b) pass: null statement, continue: skip iteration, break: exit loop.
Prime logic using for loop.
Q2(c) String functions: len(), lower(), upper().
Count vowels using loop and if.
Q2(d) List: append(), pop(); Dict: keys(), values().
Merge: d3=d1|d2
Q2(e) write() writes string; writelines() writes list of strings.
SECTION C
Q3(a) Conditional statements use if-elif-else to control flow. Grade based on marks.
Q3(b) for-loop iterates over list/string. Sum list using accumulator.
Q4(a) Function defined using def. Area of circle: πr².
Q4(b) String methods like replace(). Example: [Link]('a','b')
Q5(a) Set operations: union, intersection, difference.
Q5(b) Slicing extracts elements; tuple reversed using slicing [::-1].
Q6(a) seek() moves file pointer. Read last n lines using readlines().
Q6(b) re module handles patterns. Digits found using [Link]().
Q7(a) Inheritance shares properties; polymorphism allows multiple forms.
Q7(b) Tkinter widgets: Label, Button. Create window using Tk().