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

Python Practice Test 2

The document is a Python practice test consisting of multiple-choice and short-answer questions that assess knowledge of Python basics, control structures, data types, functions, and libraries. It includes 20 multiple-choice questions worth 1 mark each and 4 short-answer questions worth 2 marks each. The test aims to evaluate understanding of fundamental programming concepts in Python.

Uploaded by

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

Python Practice Test 2

The document is a Python practice test consisting of multiple-choice and short-answer questions that assess knowledge of Python basics, control structures, data types, functions, and libraries. It includes 20 multiple-choice questions worth 1 mark each and 4 short-answer questions worth 2 marks each. The test aims to evaluate understanding of fundamental programming concepts in Python.

Uploaded by

kawa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Practice Test

This test consists of multiple-choice and short-answer questions covering Python basics, definitions,

control structures, lists, functions, and libraries.

Multiple Choice Questions (20 marks)


Each question is worth 1 mark.

1. What is an algorithm?
a) A type of error
b) A sequence of steps to solve a problem
c) A programming language
d) A function

2. What is a program?
a) A set of stored variables
b) An algorithm written in a programming language
c) A block of reusable code
d) A collection of loops

3. Which of the following is NOT a valid Python variable name?


a) my_var
b) 2ndValue
c) value_2
d) _temp

4. What is the correct syntax to assign a value to a variable?


a) x == 10
b) 10 = x
c) x = 10
d) x => 10

5. What type of data is 'Hello, World!'


a) Integer
b) Boolean
c) String
d) List

6. What does type casting do?


a) Converts a value to another data type
b) Prints text to the screen
c) Stores multiple values
d) Compares two values
7. What will int('25') return?
a) '25'
b) 25
c) None
d) Error

8. What does input() return by default?


a) Integer
b) Boolean
c) String
d) None

9. Which of the following is a comparison operator?


a) =
b) +=
c) ==
d) //

10. What is the output of print(10 > 5)?


a) True
b) False
c) 10 > 5
d) None

11. What is the purpose of an if statement?


a) To loop through a sequence
b) To store multiple values
c) To make decisions in a program
d) To define a function

12. What does this code do?


for i in range(3): print(i)
a) Prints 1 2 3
b) Prints 0 1 2
c) Prints 0 1 2 3
d) Prints 3 2 1

13. Which of the following terminates a loop?


a) next
b) continue
c) pass
d) break

14. What will len([3, 6, 9]) return?


a) 3
b) 6
c) 9
d) Error

15. What does list.append(7) do?


a) Removes 7 from the list
b) Adds 7 to the end of the list
c) Sorts the list
d) Returns the length of the list

16. Which statement correctly defines a function in Python?


a) define function():
b) def function():
c) function def():
d) func function():

17. What does return do in a function?


a) Exits the function and returns a value
b) Skips to the next iteration
c) Prints output
d) Repeats a loop

18. What is a library in Python?


a) A collection of pre-written code that can be imported
b) A variable storing multiple values
c) A function that loops
d) A way to define conditions

19. How do you import the math library?


a) load math
b) import math
c) define math
d) include math

20. What will print(list('abc')) output?


a) ['abc']
b) ['a', 'b', 'c']
c) 'abc'
d) abc

Short Answer Questions (8 marks)


Each question is worth 2 marks.

21. Define an algorithm in one sentence.

22. Identify and correct the syntax error in the following code:
if x = 5:
print('x is 5')

23. Write a Python loop that prints the numbers from 1 to 4.

24. Explain the difference between syntax errors and logical errors with an example.

You might also like