[go: up one dir, main page]

0% found this document useful (0 votes)
55 views16 pages

PD Mock Quiz - (9) 1 PDF

The document contains a mock quiz with 30 multiple choice questions about Python programming concepts like data types, operators, functions, loops, lists, strings, etc. The questions test knowledge of basic syntax, built-in functions, behavior of code snippets, and output of programs.

Uploaded by

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

PD Mock Quiz - (9) 1 PDF

The document contains a mock quiz with 30 multiple choice questions about Python programming concepts like data types, operators, functions, loops, lists, strings, etc. The questions test knowledge of basic syntax, built-in functions, behavior of code snippets, and output of programs.

Uploaded by

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

PROGRAM DESIGN MOCK QUIZ

1. Which one of the following is valid print statement in Python?


Select one:

a.
print ("Program
Design");

b. print [Program
Design]

c.
print ("""Program
Design""")

d. print ("Program
Design")

2. Which one of the following is the correct extension of the Python file?

a. .python

b. .py

c. .pn

d. .p

3. Which one of the following statements shows a valid declaration of a string variable in
Python?

a. d = Hi There

b. d = "Hi There"
c. d == [Hi There]

d. d = [Hi There]

4. The first parameter of each method _______

a.

is set to a unique random value

b.

is always set to None

c.

is set by the first argument's value

d.

holds a reference to the currently processed object

5. Which one of the following is a valid print statement in Python?

a. print
("""Python, Java, C#""")

b. print
("Python", "Java", "C#")

c. print
("Python"), ("Java"),
("C#");

d.
print [Python, Java, C#]
6. Study the following Python code snippet and answer the question that follows:

def myFunction(b): b=b+6


print(b)

c = [2, 8, 12, 67]


myFunction(len(c))

When the above code is run, what will be the output?

a.
10

b.
67

c.
8

d.
2 8 12 67

7. Suppose myExample is [5, 8, 34, 76, 2, 56, 33], what is the result after myExample.pop(3)?

a.
[5, 8, 76, 2, 56, 33]

b.
[5, 34, 76, 2, 56, 33]

c.
[5, 8, 34, 2, 56, 33]

d.
[5, 8, 34, 76, 2, 33]
8. Which one of the following operators assigns a variable and returns the remainder?
Select one:

a. /=

b.
/

c.
%=

d.
\=

9. Study the following Python code snippet:


i = 1 while
True:
if i%4 == 0:
break
print(i) i
+= 1

What will the code print out after it is executed?

a.
123

b.
135

c.
12345

d.
111
10. Which one of the following operators is a valid comparison operator?
Select one:

a. !=

b.
AND

c. <<

d.
**

11. Which one of the following operators compares two values that are not equal to each
other?

a.
!=

b.
/=

c.
==

d.
>=

12. What is the expected output of the following snippet?

s = "Hello, Python!" print(s[-14:15])

a.
Hello, Python!Hello, Python!

b.
Hello, Python!
c.
!nohtyP ,olleH!nohtyP ,olleH

d.
!nohtyP ,olleH

13. A compiler is a program designed to __________

a. translate the source code into


machine code

b. check the source code in order


to see of it’s correct

c.
Check spelling errors on the source code

d. rearrange the source code to make it


clearer

14. Study the following Python code snippet and answer the question that follows:

When the above code is run, what will be the output?

a. Java
Python
Java

b.
Java
Python

c. Java

d.
Python
Python
Java

15. What is the output of the following list function?

a.
[100, 200, 300, 400, 500, 600]

b.
[100, 200, 300, 400, 500, 600]

c.
[100, 200, 300, 400, 500, 600]
[100, 200, 300, 400, 500, 600, 600]
d.
[100, 200, 300, 400, 500]
[100, 200, 300, 400, 500, 600]

16. What will be the output of the following Python code?


x = 1 while
True: if x %
5 == 0:
break
print(x) x
+= 1

a.
1111

b.
5432

c.
1234

d. Error

17. Which one of the following commands is used to add a new element to a list?

a. mylist.a
ddEnd(5)
b. mylist.a
dd(5)

c. mylist.a
ddLast(5)

d. mylist.a
ppend(5)

18. The __________ character is used to compare two values if they are equal to each other.

a.
=

b.
==

c.
+

d.
=+

19. Which keyword is used to represent a function in Python?

a.
Define

b. Def
c.
Fun

d.
Function

20. Study the following Python code snippet and answer the following question:

What is printed when the statements above get executed?

a.
[[7, 3, 9, 2, 5], [7, 3, 9, 2, 5]]

b.
[7, 3, 54, 2, 5]

c.
[[7, 3, 54, 2, 5], [7, 3, 54, 2, 5]]

d.
[[7, 54, 9, 2, 5], [7, 54, 9, 2, 5]]
21. What will be the output of the following Python code?
Select one:

a.

10

b.

10i

c.

20

d.

100

22. The first parameter of each method _______

a. is always set to
None

b.
holds a reference to the currently processed object

c. is set by the first argument's


value

d.
is set to a unique random value

23. Study the following Python code snippet:


What will the code print out after its executed?
Select one:

a.
TRUE
FALSE

b.
TRUE

c.
FALSE
TRUE

d.
TRUE
FALSE
TRUE

24. Suppose myExample is [5, 8, 34, 76, 2, 56, 33], what is the result after myExample.pop(3)?

a.
[5, 8, 76, 2, 56, 33]

b.
[5, 34, 76, 2, 56, 33]

c.
[5, 8, 34, 2, 56, 33]

d.
[5, 8, 34, 76, 2, 33]
25. Given the following Python code snippet, what will be printed?

presidentsList = ['Mandela', 'Mbeki', 'Zuma', 'Ramaphosa']


pos = presidentsList.index("Zuma") print (pos * 3)

a. 3

b.
6

c.
Zuma

d.
pos Zuma
26. You are told accumulate the total sum of a list of numbers, which of the following
accumulator patterns would be appropriate to achieve the desired result?

a.
Block B

b.
Block A
c.
None of the above would be appropriate for the problem.

d.
Block C

27. What is the expected output of the following snippet?

a. 3

b. the code is erroneous

c. 15

d. 7
28. Given the following Python code snippet, what will be printed?

Select one:

a.
The course is Program Design course

b.
The course is course Program Design

c.
The course is course

d.
The course is Program Design

29. What will be the value of the i variable when the while e loop finishes its execution?

a. 1
b. the variable becomes unavailable.
c. 0
d. 2

30. What is the result of the following comparison?


x = "20" y
= "30"
print(x > y)

a. True

b. False

c. None

d. The comparison causes a runtime exception/error

You might also like