Roll No…………………..
Dr B R Ambedkar National Institute of Technology, Jalandhar
B Tech 2nd Semester (CS, DS, EC, EE,)
ITFC–0101, Problem Solving Using Python
Mid-Semester Examination, 20 March-2024
Duration: 03 Hours Max. Marks: 30 Date: 20 March 2024
Marks Distribution & Mapping of Questions with Course Outcomes (COs)
Question Number 1 2 3 4 5
Max. Marks 6 6 6 6 6
CO No. 1, 2 1, 2 1, 2 2 2
Cognitive Level An Ap An, Ap Ap Ap
Section/Chapter/Unit 1 1 2 2 2
Note:
1. Attempt all the questions in sequence.
2. Answer all parts of the question at the same place. Otherwise, no marks
will be awarded.
1. Solve the puzzle: SEND + MORE = MONEY
Each letter is representing a single different digit and M is not zero.
Follow the rules of simple addition operation in mathematics. Write
a needful description in steps. [6]
2. (a) Declare variables of the following data types and assign them
appropriate values: [0.5x5=2.5]
i. Integer variable called “age”
ii. Float variable called “weight”
iii. Boolean variable called “is_student”
iv. String variable called “city”
v. List variable called “colors” containing at least three colors
(b) Write a Python expression to calculate the sum of “age” and
“weight”. Assign the result to a new variable called “total”. [0.5]
(c) Implement the following steps in Python:
i. Create a new list called “info” by combining the values of
“age”, “weight”, “is_student” and “city” using appropriate
type conversions if necessary. [0.5]
ii. Append the value of “total” to the “colors” list. [0.5]
1
iii. Print the following statement using the values from the
variables: “I am [age] years old, weigh [weight] kg, and
[am/am not] a student. I live in [city]. My favorite colors and
a total value are: [colors].” Replace the placeholders with
their respective values from the variables. Use appropriate
string formatting and type conversions if necessary. [2]
3. (a) Provide the output and explain the reason in following programs:
[0.5x6=3]
i. x=3 ii. a = True
if x>2 or x<5 and x==6: b = False
print("ok") c = True
else: if not a or b:
print("no output") print ("a")
elif not a or not b and c:
print ("b")
elif not a or b or not b and a:
print ("c")
else:
print ("d")
iii. String = “My Computer iv. x=0
Course” a=5
x1=slice(-1,-9) b=5
x2=slice(9) if a > 0:
print(String[x1]) if b < 0:
print(String[x2[1,3]])) x=x+5
elif a > 5:
x=x+4
else:
x=x+3
else:
x=x+2
print(x)
2
v. n=7 vii. list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
c=0 sum = 0
while(n): sum1 = 0
if(n>5): for elem in list1:
c=c+n-1 if (elem % 2 == 0):
n=n-1 sum = sum + elem
else: continue
break if (elem % 3 == 0):
print(n) sum1 = sum1 + elem
print(c) print(sum , end=" ")
print(sum1)
(c ) Write a program to find the sum of the following series (accept
values of x and n from user) 1 + x/1! + x2/2! + ………..xn/n! [3]
4. NIT Jalandhar is creating a distinction record in PCM (Physics,
Chemistry, Maths) of students enrolling in first year. A person named
Shashtri sitting at the front desk register students and then the result
is displayed for each student. The entries he makes for each student
during registration are: student id, name of the student and PCM
marks. The record looks like given below:
Design a system to help Mr. Shashtri in creating student record under
the following rules and guidelines:
(a). Design a void function fxn_reg() that accepts no arguments
for registering students. Marks are added in a comma separated
sequence. System should give the option for adding entries
continuously by asking ‘Do you want to continue? (Y/N)’. [3]
3
(b). Design another void function fxn_result() which takes no
argument and creates a resulty_copy. The data structure of
result_copy (displayed to Mr. Shashtri) is given below:
[2x1.5=3]
Since we do not want to disclose the calculations to Mr. Shashtri,
fxn_result() is implemented under the following rules:
i. fxn_result() contains an argument-based fruitful inner
function named public_percentage() for calculating
the percentage of each student.
ii. Function public_percentage() contains an inner
void function called private_distinction() which
takes no argument and calculates the distinction. Distinction
is set to value ‘Yes’ if percentage of marks is greater than
70% otherwise, ‘No’.
Note: The result_copy should not be created (not even empty)
until the fxn_result() is called.
5. (a) Write down the difference between array and list in python. [0.5]
(b) Create a list with 6 integers, convert it into an array. Now sort the
element of the array and display the sorted array. Sort an Array with
and without inbuilt methods. [1.5]
(c) Write a program to enter the number till the user enters 0 and at
the end it displays the count of positive and negative numbers
entered. [3]
--------------ALL THE BEST--------------
4