Mock Final Exam Python - Sol
Mock Final Exam Python - Sol
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)
Output : 3,3
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"]
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])
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
Take all the dimensions input from the user. Write a function that will
print TRUE or FALSE depending on the dimensions.
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
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².
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.