wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python review wk 1 to 5

Total questions: 38

Worksheet time: 14mins

Name
Class
Date
1.

What will this print to the screen?

print (2 * 4)

a)

2 * 4

b)

8

c)

error

d)

nothing will be printed

2.

What will be printed to the screen?

x = 5

y = "John"

print (x + y)

a)

5 + John

b)

John

c)

JohnJohnJohnJohnJohn

d)

Syntax error - you cannot add str and int together

3.

What which of the following is a valid naming convention for a variable?

a)

waterBottle

b)

WaterBottle

c)

water_bottle

d)

WATER_BOTTLE

4.

Which of the following is a valid identifier in Python?

a)

_two_percent

b)

return

c)

2_PERCENT

d)

while

5.

Which of the following data type is the postal_code?

postal_code = "555123"

a)

string

b)

int

c)

float

d)

boolean

6.

A special type of loop that never ends?

a)

Infinite loop

b)

Recursive loop

c)

Nested loop

d)

Unconditional loop

7.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
8.

The process of giving a value to a variable?

a)

Assignment

b)

Initialisation

c)

Coercion

d)

Declaration

9.

In python which is the correct method to load a module math?

a)

include math

b)

import math

c)

#include<math.h>

d)

using math

10.

What will be the printed result for the following codes?

radius = input("Enter the radius of the circle: ")

radius = 3.0

area_of_circle = 3.142 * radius * radius

print("Area is: ", area_of_circle)

a)

Area is 28.278

b)

SyntaxError: * operator cannot be use in this case

c)

TypeError: int cannot be multiply by float

d)

TypeError: float cannot be multiply by str

11.

A variable declared inside the function’s body is known as

a)

Function scope

b)

Global scope

c)

Conditional scope

d)

Local scope

12.

What is the issue with the following code?

a)

If condition will never be fulfil

b)

print cannot be use multiple times

c)

age is always lesser or equals to 18

d)

Printing conflicting statement,, should have an else statement

13.

What is the issue with the following code?

a)

age 18 should already be an adult

b)

no if statement, compile error SyntaxError

c)

missing elif statement

d)

invalid print statement within else condition

14.

What is the issue with the following code?

a)

SyntaxError, missing " : " at if statement condition

b)

should be elif instead of else

c)

missing condition after else

d)

age is an invalid variable

15.

What is the issue with the following code?

a)

SyntaxError, invalid condition

b)

NameError, variable sale is not defined

c)

Logical error, sale will never be more than 20

d)

Logical error. condition "sale >= 20 or sale <= 20" will always fulfilled

16.

FOR loops are

a)

loops which run an unknown number of times

b)

loops that iterates over a sequence in Python

c)

loops which run a known number of times

d)

repeatedly execute a statement as long as the condition provided stays true

17.

WHILE loops are

a)

loops which run an unknown number of times

b)

repeatedly execute a statement as long as the condition provided stays true

c)

loops that iterates over a sequence in Python

d)

loops which run a known number of times

18.

numbers = [2, 4, 6, 8]

for number in numbers:

print("hello!")

a)

2 hello! 4 hello! 6 hello! 8 hello!

b)

hello!

c)

2 4 6 8

d)

hello! hello! hello! hello!

19.

which of the following is a valid naming convention for a constant?

a)

SHOE_SIZE

b)

shoe_size

c)

shoeSize

d)

ShoeSize

20.

Which function is called anonymous function?

a)

Define

b)

Function

c)

Recursion

d)

Lambda

21.

The program above prints

a)

Numbers between 1 and 100 that are multiples of 5

b)

Numbers between 1 and 100

c)

Numbers between 1 and 100 divisible by 5

d)

Numbers between 1 and 101 that are multiples of 5

22.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

23.

If return statement is not used inside the function, the function will return:

a)

TypeError: All functions need a return statement

b)

0

c)

Null

d)

None

24.

Use the correct order of operations to evaluate this expression ...


6 * 8 / 2 + (15 - 6) + 3 ^ 2

a)

42

b)

32

c)

52

d)

72

25.

Example of ...?

a)

Nested loop

b)

Nested selection

c)

Recursion

d)

Sequence

26.

What is the issue with the following code?

a)

NameError,

True is a reserved word and cannot be use

b)

SyntaxError,

If statement requires a condition rather than True

c)

LogicalError,

Last print statement will always be printed

d)

LogicalError,

The else statement will never be printed

27.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

28.

for i in range(1, 6):

if i == 3:

continue

print(i, end=",")

What would be the output of the code above?

a)

1,2,3,4,5,

b)

1,2,4,5

c)

1,2,4,5,

d)

Error

29.

numbers = [5, 14, 9, 17]

for number in numbers:

if number % 3 == 0:

print(number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

30.

Python supports variable number of parameters.

a)

True

b)

False

31.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

32.

Why is the following variable name invalid:

1st_Name

a)

No special characters other than underscore

b)

The variable name starts with a number

c)

Keep names meaningful

d)

There is nothing wrong with this variable name

33.

Which of the following import only parts of a module instead of a whole module?

a)

from math import pi

b)

import math

c)

from math import *

d)

start importing math

34.

To loop through a set of code a specified number of times, which of the following function can we use?

a)

range()

b)

float()

c)

print()

d)

input()

35.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

36.

List items are indexed, the first item has index [1], the second item has index [2] etc.

a)

True

b)

False

37.

 Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

nameList["4"]

38.

Given the following code, what would be the result?

def test():

return 'abc', 100

result = test()

print(result[0])

print(result[1])

a)

SyntaxError: Unable to return more than 1 value

b)

result[0]

result[1]

c)

abc

100

d)

abc 100

abc 100