0% found this document useful (0 votes)
2 views

Final Quiz

The document is a final quiz for a programming course, consisting of seven questions related to Python programming techniques. It includes questions on output prediction, variable assignment, function definition, and loop modifications. Each question has a specific focus, such as generating outputs or modifying code to achieve desired results.

Uploaded by

Ahnaf Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Final Quiz

The document is a final quiz for a programming course, consisting of seven questions related to Python programming techniques. It includes questions on output prediction, variable assignment, function definition, and loop modifications. Each question has a specific focus, such as generating outputs or modifying code to achieve desired results.

Uploaded by

Ahnaf Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PLAN 396: Programming Techniques (January 2023)

Final Quiz (marks: 35, duration: 1 hr)


Name: Student ID:
----------------------------------------------------------------------------------------------------------------------------------------------
Q1. What will be output of the following program if the user enters an input 333 [i.e., Enter 3 digits: 333]? 2
#Python program for Q1

Input = input("Enter 3 digits: ")


Output:
if (Input == 111): y=
y = Input + 444
elif (Input == 222):
y = Input + 333
elif (Input == 333):
y = Input + 222
else:
y = Input

print ("y =", y)

Q2. Choose the values of the variables start, end, number and step so that the program produces the output displayed in
the output box. 4

#Python program for Q2


start = ?
end = ?
number = ? Answer:
step = ? Output:
-1 start =
while (start <= number <= end): 2
5 end =
number += step
8 number =
print(number) 11
step =
if number == 12:
continue

if number == 18:
break
Q3. Answer the following questions. 2+3 = 5
i) What will be the output of the following Python program?
ii) How would you change the following code segment so that the word “Python” is displayed? You are allowed
to modify/insert/delete line(s) in the body of the while loop.

#Python program for Q3 ii) Answer: i) Output:


while (letters):
letters = ['P', 'y', 't', 'h', 'o', 'n']
language = ""
i=0
while (letters):
language += letters[i]
i = i+1
letters = letters[i:]
print(language) print(language)

Q4. Answer the following questions. 2+3 = 5


i) What will be the output of the following Python program, if the user enters 01000-123 456?
ii) Modify the body of the ‘for’ loop so that the program produces the same output. Your program must not contain
any ‘continue’ statement.

#Python program for Q4


ii) Answer: i) Output:
num = input("Your phone number: ")
for ii in num:
num1 = ""
for ii in num:
if (ii == '-' or ii == ' '):
continue
num1 += ii
print(num1) print(num1)

Q5. Define a function named 'fun' so that the following code segment produces an output shown in the output box. 5

#Python program for Q5 Output: Answer:


#Define ‘fun’ here 80
print(fun()) 100

print(fun(4)) 100
100
print(fun(4, 5))
print(fun(4, 5, 80))
Q6. Choose the values of num1, num2 and num3 so that the following program displays "Python is Fun.". 9
#Python program for Q6
def just_for_fun(id, num1 = ?, num2 = ?, num3 = ?):
x = fun1 (id + num1) Answer:
y = fun2 (x*num2 + 1) num1 =
z = fun3 (y*num3 + 1)
num2 =

def fun1(a): num3 =


if (not a):
print("Python", end = " ")
return 1
Output:
else:
print("Sorry!") Python is Fun.
return 0

def fun2(b):
if (b == 1):
print("...Sorry, too much for me!")
return 0
elif (b%2 == 0):
print("is", end = " ")
return 1
else:
print("..Sorry, I lost track here! Let me try next one.", end = "...")
return 1

def fun3(c):
if (c == 1):
print("........Sorry, I am done with Python!")
elif (c%2 != 0):
print("Fun", end = ".")
else:
print("....Sorry, I failed again.")

# Enter your own student ID


Std_ID = int (input("Enter last 2 digits of your student ID: "))
just_for_fun(Std_ID%2)
Q7. Write a Python program that generates a number pyramid of N rows (user-given) using for loop. An example is
given below for N = 4. 5

Output for N = 4:
1
121
12321
1234321

You might also like