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

pcep_python[1&2]

The document contains a series of practice exam questions and answers related to Python programming concepts. It includes questions on code outputs, data types, functions, control structures, and error handling. Each question is followed by multiple-choice answers, testing the reader's understanding of Python syntax and behavior.

Uploaded by

thoale.a8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

pcep_python[1&2]

The document contains a series of practice exam questions and answers related to Python programming concepts. It includes questions on code outputs, data types, functions, control structures, and error handling. Each question is followed by multiple-choice answers, testing the reader's understanding of Python syntax and behavior.

Uploaded by

thoale.a8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Practice Exam 4

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

2. What will the output be, if we run the following code?


weekdays = ("Monday","Tuesday","Wednesday","Thursday")
weekdays.append("Friday")
print (weekdays)

A.
Monday, Tuesday, Wednesday, Thursday
B.
Friday
C.
None
D.
AttributeError: 'tuple' object has no attribute 'append'

3. How many times will it print "#"?


if x!=10:
print("#")
if x<8:
print("#")
elif x==10:
print("#")
else:
print("#")
else:
print("#"*3)

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

5. What would be printed to the console after the following code is


executed?
i=0
while i < 1:
print('Hello', end=", ")
i += 1
else:
print("World")

A. Hello
B. "Hello", World
C. Hello World
D. Hello, World

6. What will the output be after executing the following code?


Tupl = ['Python', 'Tuple']
print(tuple(Tupl))

A. ('Python', 'Tuple')
B. [Python, Tuple]
C. ['Python', 'Tuple']
D. (Python, Tuple)

7. What is the output when the following code snippet is run:


milk_left = "None"
if milk_left:
print("Groceries trip pending!")
else:
print("Let's enjoy a bowl of cereals")

A. Error
B. None
C. Let's enjoy a bowl of cereals
D. Groceries trip pending

8. What will the output be after executing the following code?


def put(x):
return [6]
val = [0, 1, 2, 3, 4, 5]
y = put(val);
print(y)

A. [6]
B. [0, 1, 2, 3, 4, 5]
C. -6
D. (0,1,2,3,4)

9. What will the output be after executing the following code?


Dict = dict({1: 'Python', 2: 'Dictionaries'})
print(Dict)

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. {'Name': 'Python', [1, 2, 3, 4], 'hi'}


B. {'Name': 'Python', 1: [1, 2, 3, 4], 2: 'hi'}
C. Syntax Error
D. {'Python', [1, 2, 3, 4], 'hi'}
13. What will the output be, if we run the following code?
lst1 = [0,1]
lst2 = [1,0]
for x in lst1 :
for y in lst2:
print(x,y)
A.
01
11
00
10
B.
01
00
11
10
C.
01
00
10
11
D.
01
11
10
00
14. What will the output be after executing the following code?
print("Hello","\nPython!")

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#

24. What is the output of the following code?


print (5//4)

A. error
B. 4
C. 2
D. 1

25. What is the output of the following code?


num = 4,
print(type(num))

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

29. Will the following code run without errors?


tup1 = (1,3,5)
tup2 = (2,4)
tup1 = tup1+tup2
print(tup1)
A. This code will run without errors.
B. This code will not run.

30. What is the output after executing the following code?


fruits = ["Apples", "Oranges", "Mangoes"]
for fruit in fruits:
if fruit != "Apples":
print(fruit, end=" ")

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

6. What is the output of the following program?


x=0
for i in range(10):
for j in range(-1, -10, -1):
x += 1
print(x)

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

9. What is the output of the following snippet of code:


def func(num):
while num > 0:
num = num - 1
num=3
func(num)

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. Values are the same


B. Values are different
C. true
D. false

11. What do you expect the following code to print:


nums = [1, 2, 3, 4]
nums.append(5)
print(nums)

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())

A. hello prof karamagi


B. HelloProfKaramagi
C. Hello prof karamagi
D. Hello Prof Karamagi

16. What will the output be after running the following code snippet?
t1 = (1, 2, 3)
t2 = ('apples', 'banana', 'pears')
print(t1 + t2)

A. (1, 2, 3), ('apples', 'banana', pears')


B. (1, 2, 3) + ('apple', 'banana'. 'pears')
C. (1, 2, 3, 'apples', 'banana', 'pears')
D. ('apple, 'banana', 'pears', 1, 2, 3)

17. What will happen if the following snippet of code is executed?


def greeting(name= ""):
print("Hello", name)
greeting()

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']

27. What do you expect to be output to the console?


if not(True):
print("Hello, World!")
else:
print("Python is Awesome!")

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

29. What do you expect the following code snippet to printout:


tupl = tuple('Python World!')
print(tupl[:-7])
A. ('P', 'y', 't', 'h', 'o', 'n')
B. ('W', 'o', 'r', 'l', 'd', '!')
C. ('n', 'o', 'h', 't', 'y', 'P')
D. [P, y, t, h, o, n]

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")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy