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

Mock Final Exam Python - Sol

This document contains a mock final exam for the course "Programming A Utility Software". It has 16 multiple choice and written response questions covering topics like Python functions, lists, strings, dictionaries, conditional statements, and writing functions. The questions get progressively more difficult. An answer key is provided for the multiple choice questions, while written responses are required for the longer questions.

Uploaded by

Divyang Pandya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
744 views

Mock Final Exam Python - Sol

This document contains a mock final exam for the course "Programming A Utility Software". It has 16 multiple choice and written response questions covering topics like Python functions, lists, strings, dictionaries, conditional statements, and writing functions. The questions get progressively more difficult. An answer key is provided for the multiple choice questions, while written responses are required for the longer questions.

Uploaded by

Divyang Pandya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Programming A Utility Software

Mock Final Exam


Wasif Jami khan

Name: Kunwardeep Singh


ID: SINK240601
Date: 22.10.2021

If you need help, ask the teacher. Any kind of plagiarism will result a
direct FAIL!!

Part 1
1. Which of the following functions return 4.0
int(3.4)
int(3.9)
eval(3.4)
round(3.5)

2. What will be displayed by the following code?


def f1(x=1, y=2):
x=x+y
y += 1
print(x, y)

Output : 3,3

3. What will be displayed when the following code is executed?


number = 6
while number > 0:
number -= 3
print(number)

Output : 3 0
4. Assume the following list definition in Python.
letters = ["a", "b", "o", "c", "p"]
What would be displayed in a Python shell for each of the following
expressions if they are evaluated in the given order? If it would give an
error then write error.

letters[1]

letters[len(letters)-2]

letters + ["x"]

letters

Output:
"b"
"c"
["a", "b", "o", "c", "p","x"]
["a", "b", "o", "c", "p"]

5. Show how to create a list of every integer between 0 and 100 ,


inclusive, named nums1 using Python, sorted in increasing order.

nums1 = list(_______________________________________)
Answer: range(0,1001) or range(1001)
6. Let nums2 and nums3 be two non-empty lists. Write a Python
command that
will append the last element of nums3 to the end of nums2 .
________________.append(_____________________).
Answer : nums3.append(nums2[len(nums2)-1]) OR
nums3.append(nums2[-1])

7. Consider the simple function given below.


def twice(n):
print(2*n)

When we compare twice(5) with 10 the Python returns False after


printing 10 as shown below. Explain why it gives False as a result of the
comparison.

print(twice(5) == 10)

10
False
Answer: Because comparing a None value to an integer would yield
False

8. In Python, strings are immutable while lists are mutable. What is the
difference?

Answer: Because if the value can change, the object is called mutable,
while if the value cannot change, the object is called immutable.
9. How does the // operator differ from the / operator? Give an example
of where // would be needed.
Answer: The Division operator (/) divides its first operand by second
operand and always returns the result as a float value whereas Floor
Division operator (//) divides its first operand by second operand and
truncates the fractional part of the result and returns it as an int value.
Floor Division operator is useful in situations where we only need the
integer part of the division operation result. For example, to
determine how many minutes are there in some given number of
seconds then we can use (//) operator.

seconds = 1888
minutes = 1888 // 60

10. What is a dictionary in python? How it is different from a list?


How to declare it? Write a small piece of code using dictionary?

Dictionary: Dictionary in Python on the other hand is an unordered


collection of data values, used to store data values like a map,
which unlike other Data Types that hold only single value as an
element, Dictionary holds key:value pair.
Where list is a collection of index values pairs

Dict = {1: 'Hey', 2: 'Hello', 3: 'Nope'}

Dict = {1: 'ABC', 2: 'new', 3: 'Tenth'}


print("Key values are: ")
print(Dict)
Part 2
11. United Airlines will only allow carry-on bags that are no more than
22 inches long, 14 inches wide, and 9 inches deep. Lets assume the 3
variables named length, width, and depth. Airport staff will use your
program to determine if this bag can be passed to carry-on or not.

Take all the dimensions input from the user. Write a function that will
print TRUE or FALSE depending on the dimensions.

l = int(input("Enter length :-"))


w = int(input("Enter width :-"))
d = int(input("Enter Depth :-"))
print( (l <= 22) and ( w<= 14 ) and (d <= 9) )

12. Write a function named extract_lesser (L, v) that, from a


list of numbers L finds all of the values less than v, puts them into a new
list, and returns that new list.

def extract_lesser (L, v):


new_list = []
for n in L:
if n < v:
new_list.append(n)
return new_list

L = [9,2,11,2,5,4,7,6,1]
v=6
print(extract_lesser(L,v))

13. Write a function that take two numbers, x and y, and returns the
sum of numbers from x to y.

a= int(input("First number:"))
b= int(input("Second number:"))
sum=a+b

print("Sum of the two numbers is:", sum)

14. Write a program that prompts the user to enter the side of a M and C
and Find out the value of E = MC².

M = int(input("Enter the first value:"))


C = int(input("Enter the second value:"))
E=M*C*C

print("The value of the equation is:", E)

15. Write a Python program to replace the last element in a list with
another list.
Sample data : [1, 3, 5, 7, 9, 10], [2, 4, 6, 8]
Expected Output: [1, 3, 5, 7, 9, 2, 4, 6, 8]

x = [1, 3, 5, 7, 9, 10]
y = [2, 4, 6, 8]
x[-1:] = y
print(x)
16. How was the question? How was your exam? How much you might
get? Also write if you have any comments!! This question has MARKS
too !!!
Exam is very excellent. Some questions were bit tricky, but I am glad that I
solved it. I can not tell exactly how much mark I would get but I am pretty sure
that my 90% Answers should be correct. I do not have any comment as I
understood the questions very well.

You might also like