wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Practice Quiz

Total questions: 60

Worksheet time: 31mins

Name
Class
Date
1.
What will the output be from the following code?
print("Hello world!\nHello world!")
a)
Hello world! Hello world!
b)
Hello world!
Hello world!
c)
SyntaxError
d)
Hello world!
2.
What will the output be from the following code?
print("Hello" + str(2) + "world!")
a)
Hello world! Hello world!
b)
Hello2world!
c)
Hello Hello world! world!
d)
SyntaxError
3.
What is syntax?
a)
Syntax is the word used to describe an error
b)
Syntax is the rules of the programming language
c)
It is used to read information
d)
It is used to output information 
4.

What is it called when code is executed based on a condition being true

a)

Sequence

b)

Selection

c)

Iteration

d)

Variable

5.

What is is called when code is repeated / looped until a condition has been met or a set number of times.

a)

Sequence

b)

Selection

c)

Iteration

d)

Variable

6.

What does the following code do? myAge = int (myAge)

a)

Converts the var (variable) myAge to a string

b)

Converts the var (variable) myAge to a integer

c)

Converts the var (variable) myAge from a integer to a string

d)

Converts the var (variable) myAge to if statement

7.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
8.

Which function decides if a string only contains numbers

a)

isalpha()

b)

isnumeric()

c)

int()

d)

string()

9.

What keyword tells the interpreter that the code which follows is a function

a)

const

b)

int

c)

def

d)

while

10.
Python identifies blocks of code by
a)
BEGIN and END keywords
b)
{ and }
c)
aligning up the starts of lines (indentation)
d)
guessing
11.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
12.
What syntax can you use to insert a line break between strings so that they appear over multiple lines?
a)
/
b)
\n
c)
\l
d)
n
13.
Joining elements together to make a string is called what?
a)
Combining
b)
Connecting
c)
Concatenation
d)
Stringing
14.
If you want more than one option for your code, what do you use (after if)?
a)

elif

b)

else

c)

ifif

d)

else if

15.

What is the output for:

people = ["John", "Rob", "Bob"]

print (people[1])

a)

John

b)

Rob

c)

Bob

d)

[ ]

16.

What is the output for:

people = ["John", "Rob", "Bob"]

print (people[-1])

a)

John

b)

Rob

c)

Bob

d)

[ ]

17.

What is the output for:

people = ["John", "Rob", "Bob"]

print (people[4])

a)

John

b)

Rob

c)

Bob

d)

Error

18.

What will be the value of the following Python expression?

4 + 3 % 5

a)

a) 7

b)

b) 2

c)

c) 4

d)

d) 1

19.

Which of the following character is used to give single-line comments in Python?

a)

a) //

b)

b) #

c)

c) !

d)

d) /*

20.

Which of the following is not a core data type in Python programming?

a)

a) Tuples

b)

b) Lists

c)

c) Class

d)

d) Dictionary

21.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

22.

What will be the output of the following Python statement?

print("abcd"[2:])

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

23.

What will be the output of:

print(“hello” +1+2+3)?

a)

a) hello123

b)

b) hello

c)

c) Error

d)

d) hello6

24.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

25.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

a) [2, 33, 222, 14]

b)

b) Error

c)

c) 25

d)

d) [25, 14, 222, 33, 2]

26.

If a=(1,2,3,4), a[1:-1] is _________

a)

a) Error, tuple slicing doesn’t exist

b)

b) [2,3]

c)

c) (2,3,4)

d)

d) (2,3)

27.

What is the final result of the expression 7 / 2 + 6?

a)

0

b)

9.5

c)

9

d)

0.875

28.

Choose the print statement below that will cause an error. Assume that num has the value 6, and name has the value Isabella.

a)

print(name + ":" )

print(num)

b)

print(name + " wants " + "num " + "candies")

c)

print(name + " wants " + "num " + "candies")

d)

print(name + ": " + num)

29.

Which one of the statements below will cause an error?

a)

ans = “hi” * 8

b)

ans = “hi” + 9

c)

ans = “hi” + “hi” + “hi”

d)

ans = (“a” * 4) + “b”

30.

Suppose you have a variable defined a = "4". What is the variable type of a?

a)

str

b)

int

c)

float

d)

number

31.

What kind of data does a float variable contain?

a)

Whole numbers

b)

Words

c)

Numbers that can have decimal components

d)

A float is not a Python variable type

32.

What does the following code print?

x = 3.4

y = 1

print(int(x))

print(x + y)

a)

3.4

4.4

b)

3

4.4

c)

3

4

d)

The code causes an error

33.

Which of the following options is the best way to get a number from the user that you plan to use in a mathematical equation?

a)

num = str(input(“Enter a number: “))

b)

num = number(input(“Enter a number: “))

c)

num = input(“Enter a number: “)

d)

num = int(input(“Enter a number: “))

34.

What is the final result of the expression 2**3?

a)

6

b)

8

c)

23

d)

That is not a valid Python expression.

35.

On which line of code will Python FIND the error?

weight = input("How much do you weigh? ")

oz_water = weight / 2

print("You should drink " + str(oz_water))

print("ounces of water every day if you weigh " + weight)

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

36.

In what order should these statements be executed in order to get input from the user and print out a confirmed result?:

A) response = input("Do you like cheese? ")

B) print("You have chosen " + confirm)

C) print("You responded " + response)

D) confirm = input("Are you sure? ")

a)

A, B, C, D

b)

B, C, A, D

c)

A, C, D, B

d)

C, B, A, D

37.

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?

a)

third_answer

b)

thirdAnswer

c)

thirdanswer

d)

3rdAnswer

38.

Which of the following choices is NOT a Python variable type?

a)

int

b)

str

c)

float

d)

number

39.

How would you round the number held in the variable pi to 3.14?

pi = 3.14159265

a)

round(pi)

b)

round(pi, 3)

c)

round(pi, 3)

d)

round(pi, 2)

40.

Why should you use round when you compare two numbers that have type float?

a)

If you don’t, Python will only compare the whole part and discard the decimal part.

b)

You don’t have to, but it’s good style. All of the comparisons will still work out the same way.

c)

Sometimes numbers can be rounded in unexpected ways based on how Python computes them. Therefore, it is best to use round in order to make sure both numbers are rounded the same way.

d)

You should always use round when you compare two numbers, even if they are of type int.

41.

What will be the output of this program?

number = 5

greater_than_zero = number > 0

if greater_than_zero:

-> print(number)

# ignore the ->, it's showing the indent

a)

0

b)

5

c)

True

d)

Nothing will print

42.

What will be the output of this program?

number = 5

greater_than_zero = number > 0

if greater_than_zero:

-> if number > 5:

-> -> print(number)

# ignore the ->, it's showing the indents

a)

0

b)

5

c)

True

d)

Nothing will print

43.

What will be the output of this program?

a)

5

b)

5

7

c)

5

7

8

d)

5

8

44.

What will the following program print when run?

a)

1

b)

1

3

5

c)

1

4

d)

1

4

5

45.

What will the following program print when run?

a)

1

b)

1

3

5

c)

1

4

d)

1

4

5

46.

What does this program print?

a)

But green is the color of grass!

Blue is the best

But yellow is the color of school buses!

b)

But green is the color of grass!

c)

But green is the color of grass!

I like red, too!

Blue is the best

But yellow is the color of school buses!

d)

Blue is the best

47.

Which of the following for loops would print the following numbers?

0

1

2

3

4

5

a)

for i in range(5):

-> print(i)

b)

for i in range(1, 5,1):

-> print(i)

c)

for i in range(6):

-> print(i)

d)

for i in range(0, 5, 1):

-> print(i)

48.

Which of the following for loops would print the following numbers?

3

5

7

9

a)

for i in range(3, 10, 2):

-> print(i)

b)

for i in range(3, 9, 2):

-> print(i)

c)

for i in range(9):

-> print(i)

d)

for i in range(3,9):

-> print(i)

49.

What is the value of num when this loop completes?

num = 0

for i in range(2, 8, 2):

-> num = num + i

a)

2

b)

8

c)

12

d)

20

50.

Which of the following for loops will give the same values for i as the loop below?

for i in range(10):

a)

for i in range(11, 0):

b)

for i in range(10, 0, -1):

c)

for i in range(0, 10):

d)

for i in range(0, 11, 1):

51.

What does this program print?

a)

It’s still a nice day

It’s still a nice day

b)

It’s still a nice day

It’s still a nice day

It’s still a nice day

c)

It’s still a nice day

It’s still a nice day

It’s still a nice day

It’s still a nice day

It’s still a nice day

d)

It’s still a nice day

It’s still a nice day

It’s still a nice day

It’s still a nice day

52.

Which of the following while loops would continue to loop as long as num has values between the range of 3-12, exclusive?

a)

while num > 12 and num < 3:

# do something with num

b)

while num < 12 or num < 3:

# do something with num

c)

while num <= 12 and num >= 3:

# do something with num

d)

while num < 12 and num > 3:

# do something with num

53.

Which of the following while loops will cause an infinite loop?

a)

secret_num = 10

while secret_num == 10:

-> secret_num = secret_num - 1

b)

secret_num = 10

while secret_num == 10:

-> print(secret_num)

c)

secret_num = 10

while secret_num > 0:

-> secret_num = secret_num - 1

d)

secret_num = 10

while secret_num != 10:

-> print(secret_num)

54.

When would a while loop be a better control structure to use than a for loop?

a)

When you need to repeat multiple commands

b)

When you need to repeat something 5 times

c)

When you don’t know how many times something will need to repeat

d)

When the user is inputting how many times to repeat something

55.

What will be printed to the screen when this program is run?

a)

0

1

0

1

b)

0

2

c)

0

1

0

1

0

1

d)

1

2

1

2

1

2

56.

What is the value of sum when this code completes?

a)

8

b)

9

c)

20

d)

0

57.

What will be printed to the screen when this program is run?

a)

100

0

-75

-125

-150

b)

-150

c)

-175

d)

175

58.

What does this program print?

a)

0

1

2

b)

0

1

2

4

5

6

7

8

9

c)

0

1

2

3

4

5

6

7

8

9

d)

0

1

2

3

59.

What is the benefit of using the break command in this program?

a)

The user can enter as many answers as they want

b)

The program will break out of the loop as soon as the user enters the magic_number

c)

The loop will prompt the user to enter a number no matter what input they give

d)

The loop will give the magic_number after a certain number of tries

60.

If the user enters ‘4’, I want the loop to exit. At which line should the break command be placed in order to end the loop when the user enters this value?

a)

On line 3

b)

On line 5

c)

On line 7

d)

On line 9