Press copy
BAHAUDDIN ZAKARIYA UNIVERSITY, MULTAN
Exam: Final Term Course Title: Computer Programming using Python
Class: BS Mathematics Semester: 3rd Course Code: COMP 201
Time Allowed: 2:30 Hours Session: (2022-26) Total Marks: 60
Sr. No. of
No Questions Marks
Note:
Attempt all questions.
Each mark and symbol is meaning full in a source code. So use them carefully.
Q-1
(a) Define escape character. What will the following statement display?
print("b\\ta\no\ta\to\ta\n")
(b) What is output of following snippet:
List = [[4,2,1,6],[9,5,-2],[ ]]
L1 = List[0:2]
L2 = List[:1]
L3 = List[1:]
print(L1)
print(L2)
print(L3)
(c) Write Python expression for the following:
|√ |
(d) Differentiate between count-controlled and sentinel-controlled repetition structures.
Write a Python statement (or general structure) for each of these two.
(e) Write a program that input a number and finds whether it is even or odd.
(f) What output of the (g) What output of the following snippet:
following snippet: # function definition
# easy question def my_fun():
C = 45 print("This is a tester function.")
print(id(C))
C = str(C) my_fun()
print(id(C)) print("Python is so simple.")
my_fun()
my_fun()
(h) Write the use of built-in function len()with a string in python. Give one example.
(i) What is the output of the following snippet:
import numpy as np
M = [Link]([87,96,70,100,87,90])
M1 = [Link]()
M[3] = M[3]+10
print(M)
print(M1)
(j) Write the difference between local and global variables in python?
Q-2 Write down any 5 rules for setting variable names in Python.
Write a Python program that inputs three integers prints their sum, average, and
Q-3
product.
P.T.O
Press copy
Write a program to approximate the value of by using formula:
Q-4 ∑
An electric power supply company charges its residential consumers for the electricity units
according to the tariff as below:
Rs. per unit (KW/Hour) for the first units,
Rs. per unit (KW/Hour) for the next units (i.e., units from 101 to 200),
Q-5 Rs. per unit (KW/Hour) for the next units (i.e., units from 201 to 300),
Rs. per unit (KW/Hour) for the next units (i.e., units from 301 to 700), and
Rs. per unit for rest of the units (i.e., units after 700).
Write a program that asks the user to enter the number of units consumed and finds the
electricity charges for an arbitrary number of consumers.
Write a Python program that asks and receives a positive integer ‘N’ and then compute and
Q-6 print the factorials of all the integers from to N. Write a Python Function to obtain the
factorial of the integer.