0% found this document useful (0 votes)
23 views2 pages

ZF D5 L Qa BPC Fohk JD

Uploaded by

Plash Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

ZF D5 L Qa BPC Fohk JD

Uploaded by

Plash Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Roll No…………………..

Dr B R Ambedkar National Institute of Technology, Jalandhar


B Tech 2nd Semester (CS, DS, IT, BT, EC, EE, VL) (b) Provide the output and explain the reason in the following programs:
ITFC0101, Problem Solving using Python [1*6 = 6]
End-Semester Examination, May-2024
a. if i<j:
Duration: 03 Hours Max. Marks: 50 Date: May 15, 2024
if j<k:
Marks Distribution & Mapping of Questions with Course Outcomes i = j
(COs) else:
Question Number 1 2 3 4 5 j = k
Max. Marks else:
10 11 10 9 10
if j<k:
CO No. 1 1,2 4 3 2,3 j = i
*Cognitive Level R,An U,Ap Ap An,E E,C else:
**Section/Chapter/Unit 1 1,2 2 3 3 i = k
print(i, j, k)
Note:
1. Attempt all the questions. What will the above code output of code print if i, j, and k have the
2. Write all your answers with complete justification. following value?
i. i= 3, j= 5, k= 7 ii. i= -2, j= -5, k= 9

Q1. (a) Imagine that you have 26 constants, labeled A through Z. Each b. print('p' + 'q' if '12'.isdigit() else 'r' + 's')
constant is assigned a value in the following way: A = 26^1, B =
25^2, C = 24^3, D = 23^2, and so on till Z = 1^26. (i) Draw a c. x = y = 40
flowchart to calculate the sum of all 26 values using recursion. (ii) z = 1 + (x if x > y else y) + 2
Find the exact numerical value to the following equation: (Y - A) * print(z)
(Y - B) * (Y - C) * ... * (Y - Z) and justify the reason for the
generated output. [6]
d. print(True*2)

e. print("Hello {0[0]} and {0[1]}”.format(('foo',


(b) Write down the advantages of script mode over interactive mode 'bin')))
in Python and vice versa. Illustrate with the help of Python code number = 5
f.
in both modes. [4] while number <= 5:
if number < 5:
number = number + 1
Q2. (a) Explain the concept of data types in Python. Show its hierarchy.
print(number)
Provide examples of different data types supported by Python code
and describe when each data type might be used in a program. [5]

1 2
Q3. Assume, it is the end of the semester and the students would like to Q5. (a) Examine the following function percentage: [4]
know the GPA they achieved for the subjects they registered and sit
for the final exam. You are going to develop a program that can def percentage(marks, total):
try:
calculate GPA for the students according to the grade they get and
percent = (marks / total) * 100
the subject credit hours. The point scale for the grade is shown
except ValueError:
below. Grade Point Scale A 4.0, A- 3.7 ,B+ 3.3, B 3.0, B- 2.7, C+ print('Value Error')
2.3, C 2.0, C- 1.7, D+ 1.3, D 1.0, D- 0.7, F= 0 Note the formulae except TypeError:
below to calculate the GPA. 𝐺𝑃𝐴 = 𝒔𝒖𝒎 𝒐𝒇 (𝒔𝒖𝒃𝒋𝒆𝒄𝒕 𝒄𝒓𝒆𝒅𝒊𝒕 𝑥 print('TypeError')
𝒈𝒓𝒂𝒅𝒆 𝒑𝒐𝒊𝒏𝒕) / 𝒕𝒐𝒕𝒂𝒍 𝒄𝒓𝒆𝒅𝒊𝒕 𝒂𝒕𝒕𝒆𝒎𝒑𝒕𝒆𝒅 Please make sure to except ZeroDivisionError:
apply the loop concept. [10] print('ZeroDivisionError')
except:
print('any other error')
else:
Q4. (a) Given a tuple test_tup = (4, 5, 4, 5, 6, 6, 5). Write a program to
print(percent)
find the frequency of each element. Output like as: {4: 2, 5: 3, 6: 2} finally:
[4] print('Function percentage completed')
(b) Given a list of employee records employee_data where each
record is a tuple (employee_id, name, age, department, Determine the output for the following function calls:
salary), write a Python program using list comprehension to: i. percentage(50.0,150.0)
i. Create a list young_employees containing the names ii. percentage(50.0,0.0)
of employees under 30 years old. iii. percentage(‘50.0’,’150.0’)(15)
ii. Create a list high_earners containing tuples
(employee_id, salary) for employees earning (b) Write a program in Python that first checks using a try-except
more than 80,000 per year. [5] block whether a file named "file1.txt" exists or not, and if the file
does not exist, it must return an appropriate error message; if the file
employee_data = [ exists, the program should open the file, read its contents, and then
(1001,'John Doe', 32, 'Engineering', 75000), output the following information: [6]
(1002,'Jane Smith', 28, 'Marketing', 65000), i. Count of alphabetic characters
(1003,'Michael Johnson', 45, 'Sales', 90000),
ii. Count of lowercase letters
(1004,'Emily Davis', 25, 'HR', 55000),
iii. Count of uppercase letters
(1005,'David Wilson', 38, 'Finance', 85000),
(1006,'Samantha Brown', 29, 'IT', 70000), iv. Count of blank spaces
(1007,'Robert Taylor', 51, 'Operations', 95000)
]
*****
3 4

You might also like