wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz - Data type, If/Else, Coding

Total questions: 30

Worksheet time: 20mins

Name
Class
Date
1.
In python the ' STRING data type' can be defined as...?
a)
holds alphanumeric text
b)
hold whole numbers
c)
holds numbers with a decimal point
d)
holds either a true or false value
2.
In python the ' INTEGER data type' can be defined as...?
a)
holds alphanumeric data as text
b)
holds whole numbers
c)
holds numbers with a decimal point
d)
holds either ‘true’ or ‘false’
3.
In python the ' FLOAT data type' can be defined as...?
a)
holds alphanumerical data
b)

holds whole numbers

c)

holds a decimal point in a number

d)
hold either true or false
4.
In python the ' BOOLEAN data type' can be defined as...?
a)
holds alphanumerical data
b)
holds whole numbers
c)
holds a number with a decimal point
d)
holds either true or false
5.
What is the correct definition for a VARIABLE?
a)
a changeable value, such as a score in a computer game.
b)
a value that cannot be changed
6.
What data type would be used for storing someone's telephone numbers?
a)
Float (using a decimal point)
b)
Integer (just whole numbers)
c)
String (alphanumerical data)
7.
If we needed to store information such as a POSTCODE in PYTHON, what data type would we use?
a)
String (alphanumerical)
b)
Float (decimal point)
c)
Boolean (true or false)
8.
What is the correct definition for 'pseudo code?'
a)
a notation resembling a complex programming language, used in program design.
b)
a notation resembling a simplified programming language, used in program design.
9.
What is the function of the code:amount = int(input("Enter a conversion into pounds:))currency = input ("press 1 for indian rupees, 2 for Chinese yuan or 0 to exit:")
a)
to find the total amount of currency altogether
b)
to calculate and convert the exchange rates.
10.

what is the code for a STRING in python?

a)

str

b)

stri

c)

string

11.
what is correct code for INTEGER in python?
a)
in
b)
ing
c)
int
12.
What best defines an IF statement in python?
a)
Is an embedded string with a variable
b)
An IF statement checks to see if a statement is true or false and then does one of two things depending on the result.
13.
I am 71 years old! What will the output be?: IF you are 70 or older, say “You are aged to perfection!” ELIF you are exactly 50, say “Wow, you are half a century old!” ELSE say “You are a spring chicken!”
a)
“You are aged to perfection!”
b)
"Wow, you are half a century old!"
c)
"You are a spring chicken!"
14.
I am 18 years old! What will the output be?: IF you are 70 or older, say “You are aged to perfection!” ELIF you are exactly 50, say “Wow, you are half a century old!” ELSE say “You are a spring chicken!”
a)
"You are aged to perfection"
b)
"Wow, you are half a century old!"
c)
"You are spring chicken!"
15.
Stores a piece of data, and gives it a specific name
a)
variable
b)
whitespace
c)
interpreter
d)
modulus
16.
Surrounds multi-line comments
a)
"""
b)
**
c)
#
d)
%
17.
A data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulus
d)
interpreter
18.
The correct way to write a variable in Python?
a)
myVariable = 10
b)
my Variable = 10
c)
myVariable is 10
d)
myVariable: 10
19.
To solve a problem that requires the user to enter 10 numbers would use what type of iteration?
a)
While loop
b)
For loop
c)
Variable
d)
Selection
20.

What will the output of the following code be?

for i in ["A", "b", "3"]:

print(i)

a)

Error

b)

"A"

"b"

"3"

c)

A, b, 3

d)

A

b

3

21.

What is the output of the code below?

x = 5

if x == 0:

print("x is 0")

elif x > 1:

print("x is greater than 1")

elif x > 3:

print("x is greater than 3")

a)

x is 0

b)

x is greater than 1

c)

x is greater than 3

22.

for a in range(3):

print(a)

a)

1

2

3

b)

0

1

2

c)

1 2 3

d)

Error

23.

What is the value of b?

a = 0

b = a

a = 3

a)

0

b)

3

24.

Which of the following commands exists?

a)

.upper()

b)

.casefold()

c)

.destroy()

d)

.TextChar

25.

What is the output of this code?

string = "Python Test"

for i in string.split():

print (i, end=", ")

a)

P, y, t, h, o, n, T, e, s, t,

b)

Python, Test,

c)

P, y, t, h, o, n, ,T, e, s, t,

26.

What is the output of the code?

a = (33, 55)

a.append(22)

print(a)

a)

33 55 22

b)

33

55

22

c)

33, 55, 22

d)

Error

27.

What is the output of the code?

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

print(people[1])

a)

Bob

b)

John

c)

Mark

d)

Error

28.

What is the output of the code?

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

print(people[-1])

a)

Bob

b)

John

c)

Mark

d)

Error

29.

What is the output of the following?

i = 1

while True:

if i%2 == 0:

break

print(i)

i += 2

a)

1

b)

1 2

c)

1 2 3 4 5 6...

d)

1 3 5 7 9 11....

30.

What is the output of the following?

for i in range(10):

if i == 5:

break

else:

print(i)

else:

print("Here")

a)

0 1 2 3 4 Here

b)

0 1 2 3 4 5 Here

c)

0 1 2 3 4

d)

1 2 3 4 5