S.G.T.B.
Khalsa College
B.Sc.(Hons.) Physics Mathematical Physics - I (2025-26) Due Date and Time :
2222011101 P2 Lab Assignment # 1 (18.08.25) 18.08.2025, 11:59PM
Teacher: Mamta Introduction to Python Max. Marks : 60
Instructions:
1. Students who do not follow the submission instructions, including the prescribed file naming convention,
will incur a penalty of marks.
2. Please include meaningful comments in the program.
3. Use appropriate names for variables, files, functions and programs.
4. All input commands should print proper instructions for the user regarding what to enter.
5. You are encouraged to discuss among yourself but do not copy answers or code from others.
6. Plagiarism will be strictly penalised.
7. All theory questions along with their answers are to be written in the practical file. All flow charts
and algorithms asked in the programming questions are to be also written in practical file.
8. All programs to be submitted via Google form shared with you as per the following instructions:
Submission Instructions:
(a) Make a folder with the name A1-YY XXXX where YY is your group number (P1 or P2) and
XXXX are the last four digits of your roll no. For example, a student in group P2 with first name
ABCD and with roll no 2025PHY1006 will make a folder with name A1-P2 1006.
(b) Put all files relevant to the assignment, namely
• All .py files – one for each programming question with relevant comments.
– Each file should have name as A1-ques N.py . For example the file for programming
question no 1 should be named as A1-ques 1.py.
– Each program should have your Roll No and Name as comment in the first line and
Question as comment in the next line.
– The output should start with a print statement
My Roll No. = XXXX
Output for Question No N
for the Nth question.
• A .pdf file containing all the python programs and the outputs with figures.
(c) Compress this folder into file with name A1 XXXX -Name.zip or A1 XXXX.tar.gz and upload
this file on the google form shared with you. PLEASE DO NOT USE .RAR files .
Theory Questions
1. Consider the python snippet: [2]
a = input ( " Enter first : " ) # user types 12
b = input ( " Enter second : " ) # user types 3
print ( " Result : " , a * 2 + b )
Write the exact output shown on screen. Justify your answer.
2. Write the output with justification for the following code assuming the user enters 7. [2]
x = int ( input ( " Enter a number : " ) )
print ( x > 5 and x % 2 == 0 or x == 7 )
3. Predict the output and explain: [2]
x = 23
y = 5
print ( x // y , x % y )
print ( - x // y , -x % y )
4. Write the exact output (including spaces and punctuation) for: [2]
x = 4
y = 3
print ( " x = " , x , " , y = " , y )
print ( " x * y = " , x *y , " and x ** y = " , x ** y )
5. Identify error(s) in the following code and rewrite the correct code [3]
name = input ( " Your name ? " )
if name = " Bob "
print ( " Hello " , name )
else
print ( " Hi there ! " )
6. The intention is to print whether the input integer is even or odd. Identify error(s) and provide a [3]
corrected version.
n = int ( input ( " Enter integer : " ) )
if n % 2 == 0:
print ( " Even " )
else :
print ( " Odd " )
7. Given the following flowchart (Figure 1), write the corresponding Python code. [3]
Figure 1: Flowchart for Theory Q6
What will be the output if the user gives input : 0
8. Consider the following Python code: [3]
m = int ( input ( " Marks : " ) )
if m >= 50:
print ( " Pass " )
elif m >= 80:
print ( " Distinction " )
else :
print ( " Fail " )
(a) What will be the output if the user enters the values (i) 95, (ii) 85, and (iii) 45 ?
(b) Which branch is effectively unreachable and why.
(c) Rewrite the code so that all so that all branches can potentially execute..
Programming Questions
1. Write a Python program that takes a user’s first name and city as inputs (two separate inputs) and [5]
prints:
Hello, <name> from <city>!
Use a single print with f-string formatting.
2. Write a Python program which accepts a string from a user and prints the same name with all letters [2]
in lower case. Find the correct string method for the same.
3. Write a Python program that takes a sentence as input from the user, splits it into parts at the comma [2]
and prints each part on a separate line. Show output for a sentence having (i) no comma, (ii) 2 commas.
4. Read two numbers a and b. Print: [5]
• a + b, a - b, a * b
• a / b if b != 0, otherwise print a clear message that division is not possible.
5. Write a python code to perform following task: [5]
Read a person’s age.
If age < 5: print Free.
Else if 5 ≤ age < 18: print Child Fare.
Else if age≥ 60 : print Senior Fare.
Otherwise print Adult Fare.
6. Write the algorithm, draw the flowchart and write python code to read one integer n and print whether [5]
it is "Multiple of 3" or not.
7. Write the pseudocode, draw the flowchart and write python code to arrange given three numbers in [10]
descending order. Use if-elif-else only (no built-ins like max).
8. Write the algorithm/pseudocode, draw the flowchart and write python code for the following task: [10]
Take as input three float numbers a, b, c from the user and prints the real roots of the quadratic equation
ax2 + bx + c = 0. Print the error message if roots are complex.