pcep_python[1&2]
pcep_python[1&2]
Practice Exam 5
Practice Exam 6
Practice Exam 7
Practice Exam 8
Practice Exam 9
Practice Exam 10
Practice Exam 1
1. What will the output be after executing the following code snippet?
print(9** 3 ** 0 ** 1)
A. 3
B. 9
C. 1
D. 18
A.
Monday, Tuesday, Wednesday, Thursday
B.
Friday
C.
None
D.
AttributeError: 'tuple' object has no attribute 'append'
A. 3
B. 1
C. 2
D. 4
4. What is the output of this code when "robert" is entered by the user when
prompted?
name = input()
print(name == " Robert ")
A. True
B. error
C. Robert
D. False
A. Hello
B. "Hello", World
C. Hello World
D. Hello, World
A. ('Python', 'Tuple')
B. [Python, Tuple]
C. ['Python', 'Tuple']
D. (Python, Tuple)
A. Error
B. None
C. Let's enjoy a bowl of cereals
D. Groceries trip pending
A. [6]
B. [0, 1, 2, 3, 4, 5]
C. -6
D. (0,1,2,3,4)
A. dict{'Python', 'Dictionaries'}
B. dict({'Python', 'Dictionaries'})
C. {'Python', 'Dictionaries'}
D. {1: 'Python', 2: 'Dictionaries'}
10. What is the output of this code after the user inputs "Python" when
prompted?
word = input()
print(word*3)
A. PythonPythonPython
B. error
C. Python*3
D. Python Python Python
11. What will the output be after running the following code?
def put(x):
x[-1] = 6
val = [0, 1, 2, 3, 4, 5]
put(val);
print(val)
A. [0,1,2,3,4,5]
B. (0,1,2,3,4,5,6)
C. [0, 1, 2, 3, 4, 6]
D. [1,2,3,4,5,6]
12. What will the output be, if we execute the following code?
Dict = {'Name': 'Python', 1: [1, 2, 3, 4], 2: "hi"}
print(Dict)
A. Hello "\nPython!"
B. Hello Python!
C. Hello
Python!
D. Hello \nPython!
15. What will the output be after running the following code snippet?
full_name = "robert method karamagi"
print(full_name.title())
A.
Robert method karamagi
B.
Robert method Karamagi
C.
Robert Method Karamagi
D.
ROBERT METHOD KARAMAGI
16. What will the output be after calling the following function?
def sum(a,b):
return a * b
return a + b
print(sum(2,3))
A. 6
B. Syntax Error
C. 6 5
D. 5
17. What will the output be after running the following code snippet?
age = 19
print(not age > 18 and age < 20)
A. 19
B. SyntaxError
C. True
D. False
18. What would be printed to the console after the following code is
executed?
for num in range(1, 10, 2):
print(num, end = ",")
A. 2,4,6,8,10
B. 2,4,6,8
C. 1,3,5,7,9
D. 1,3,7,9
19. What will the output be after executing the following code snippet?
programming_language = "Python 3"
print (programming_language[-1])
A. Nothing is printed
B. 3
C. -1
D. P
20. What will the output be, if we run the following code?
dict1 = {1:"One", 2:"Two"}
dict1[2] = "One"
print(dict1)
A. No Output
B. {1: One, 2: Two}
C. {1:"One", 2:"One"}
D. {1: "One",1 : "One"}
21. What will the output be after running the following code?
nums = [1, 2, 3, 4, 5, 6, 7]
print(nums[::-1])
A.
[1, 2, 3, 4, 5, 6]
B.
[7, 6, 5, 4, 3, 2, 1]
C.
[0, 1, 2, 3, 4, 5, 6]
D.
[7, 1, 2, 3, 4, 5, 6]
22. What is the output of this code when 'wi' and 'fi' are entered by the user
when prompted and stored in a and b, respectively?
a = input()
b = input()
print(a + b * 3)
A.
wifiwiwifi
B.
wifiwifiwifi
C.
wifififi
D.
wififififi
23. What will the output be after executing the following code?
print("Hello","World","Python", sep="#")
A. Hello#World#Python
B. error
C. #Hello#World#Python
D. HelloWorldPython#
A. error
B. 4
C. 2
D. 1
A. error
B. <class 'int'>
C. <class 'tuple'>
D. Invalid Data Type
26. What will the output be after running the following code?
def oddoreven(num):
if (num % 2 == 0):
print('even')
else:
print("odd")
oddoreven(13)
A.
odd
B.
even
27. What will the output be after running the following code?
def swap(x, y):
z = x;
x = y;
y = z;
x=5
y = 10
swap(x, y)
print(x , y)
A. error
B. 5 10
C. 10 5
D. Prints nothing
28. What will the output be after running the following code?
def default(x, y=5):
print( y , x)
default(1)
A. Prints nothing
B. 1 5
C. error
D. 5 1
A. Oranges Mangoes
B. Apple Mangoes
C. Apple Oranges
D. Apple Oranges Mangoes
Practice Exam 2
1. What do you expect the following code will print given the first input is
apple (stored in variable a) and the second input is banana (stored in
variable b)?
a = input()
b = input()
x, y = b, a
print(x, y,sep="::")
A. apple:banana
B. apple::banana
C. banana:apple:
D. banana::apple
2. What will the output be after running the following code snippet?
def myfun(num):
if num >= 4:
return num
else:
return myfun(1) * myfun(2)
print(myfun(4))
A. 0
B. 4
C. 2
D. 1
3. What will the output be after running the following code snippet?
lst = ["apples","bananas", ""]
lst.remove("apples")
print(lst)
A. ['bananas', '']
B. ['bananas']
C. ['apples']
D. ['apples', 'bananas', '']
4. What will the output be after running the following code snippet?
nums = [1, 2, 3, 4, 5, 6, 7]
print(nums[::-1])
A. [7, 6, 5, 4, 3, 2, 1]
B. [1, 2, 3, 4, 5, 6, 7]
C. [1, 2, 3, 4, 5, 6]
D. [2, 3, 4, 5, 6, 7]
5. What will the output be after running the following code snippet?
a = 0b1011
b = 0b1001
print(bin(a ^ b))
A. 0b01
B. 0b11
C. 0b10
D. 10
A. 1
B. 9
C. 10
D. 90
7. What will the output be after running the following code snippet?
lst1 = [1, 4, 8, 16]
lst2 = [4, 16, 8, 1]
print(lst1 == lst2)
A. Not equal
B. Equal
C. False
D. True
8. What will the output be after running the following code snippet?
print(9 % 2 ** 4)
A. 4
B. error
C. 1
D. 9
A. 2
B. 3
C. Nothing is printed
D. 0
10. What will the output be after running the following code snippet?
if 1 == 1.0:
print("Values are the same")
else:
print("Values are different")
A. [5, 4, 3, 2, 1]
B. [1, 2, 3, 4, 5]
C. [1, 2, 3, 4]
D. [5, 1, 2, 3, 4]
12. What will the output be after running the following code snippet?
x = 100
def glob():
global x
x = 20
glob()
print(x)
A. 100
B. 20
C. error
D. x not defined
13. What will the output be after running the following code snippet?
nums = [1, 2, 3]
for i in range(len(nums)):
nums.insert(i,i+1)
print(nums)
A. [1, 1, 2, 2, 3, 3]
B. [1, 2, 3, 1, 2, 3]
C. [1, 2, 3, 3, 2, 1]
D. [1, 2, 3]
14. What will the output be after executing the following code snippet?
i=0
while i > 3:
i+=1
print("Yes")
else:
i -=1
print("No")
A. error
B. Yes
C. No
D. 0
15. What will the output be after running the following code snippet?
s1="Hello Prof Karamagi"
print(s1.capitalize())
16. What will the output be after running the following code snippet?
t1 = (1, 2, 3)
t2 = ('apples', 'banana', 'pears')
print(t1 + t2)
A. Hello ""
B. Hello "name"
C. Hello, name
D. Hello
18. What will the output be after running the following code snippet?
print("Robert","Karamagi", sep=",")
A. Robert,Karamagi
B. Robert ","Karamagi
C. Robert Karamagi
D. RobertKaramagi
19. What will the output be after running the following code snippet?
marks = 55
if marks > 70 and marks < 80:
print("First Class")
elif marks > 60 and marks < 70:
print("Second Class")
elif marks >50 and marks < 60:
print("Third Class")
else:
print("No Class")
A. No Class
B. First Class
C. Second Class
D. Third Class
20. What will the output be after running the following code snippet?
def tripler(num):
def doubler(num):
return num *2
num = doubler(num)
return num * 3
print(tripler(2))
A. 64
B. 12
C. 7
D. 6
21. What will the output be after running the following code snippet?
print(end='',sep='--')
A. --
B. ''
C. Nothing; no newline/blankline
D. '--'
22. What will the output be after running the following code snippet?
nums = [[1, 2, 3]]
initializer = 1
for i in range(1):
initializer *= 10
for j in range(1):
nums[i][j] *= initializer
print(nums)
A. [[10, 2, 3]]
B. [[1, 2, 3]]
C. [[10, 1, 2, 3]]
D. [[10]]
23. What will the output be after running the following code snippet?
val = 5
print("less than 10") if val < 10 else print("greater than 10")
A. not valid
B. greater than 10
C. less than 10
D. syntax error
24. What will the output be after running the following code snippet?
d = {'one':2,'two':2}
d['one'] = 1
print(d)
A. {'one': 0, 'two': 1}
B. {'one': 0, 'two': 2}
C. {'one': 1, 'two': 2}
D. {'one': 1, 'two': 0}
25. What will the output be after running the following code snippet?
print("Python"*2,sep=',')
A. Python,Python
B. Python','Python
C. PythonPython
D. Python,*2
26. What will the output be after running the following code snippet?
def myprint(*val):
print(val)
myprint("Peter","Piper","Pickled","Pepper")
A. error
B. ('Peter', 'Piper', 'Pickled', 'Pepper')
C. ('Peter')
D. ['Peter', 'Piper', 'Pickled', 'Pepper']
A. false
B. true
C. Python is Awesome!
D. Hello, World!
28. What will the output be after running the following code snippet?
print (10/5)
A. error
B. 2
C. 2.0
D. 5
30. What will the output be after running the following code snippet?
def fun(a = 3, b = 2):
return b ** a
print(fun(2))
A. 6
B. 4
C. 9
D. error
Practice Exam 3
1. What will be the output after running the following code?
def func1() :
print("func1")
def func2():
print("func3")
def func3():
print("func3")