wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python

Total questions: 30

Worksheet time: 21mins

Name
Class
Date
1.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

2.

What is the correct extension for python files ?

a)

.py

b)

.pyth

c)

.python

3.

Which of the following is True

a)

Python is an interpreted language

b)

Python is a compiled language

c)

Python is a scripting language

d)

Python is an Object oriented language

4.

What is the output of this expression, 3*1**3

a)

27

b)

9

c)

3

d)

1

5.

Which of the following is an invalid variable?

a)

my_string_1

b)

1st_string

c)

foo

d)

-

6.

is Python case sensitive when dealing with identifiers?

a)

yes

b)

no

c)

machine dependent

d)

none of these

7.

Output of this code?

a)

[2,4,6,8,10]

b)

['2','4','6','8','10']

c)

[0,2,4,6,8]

d)

[10,8,6,4,2]

8.

The count() method returns the number of times the specified element appears in the list.

What is the output of this code?

a)

3

b)

2

c)

1

d)

0

9.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
10.

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)

d)

nameList["4"]

11.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

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

d)

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

12.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
13.

A dictionary is an example of a sequence ...

a)

True

b)

False

14.
What data type is this?
quiz = {"Do you help out at home? ":"yes",        
"Do you beleive in Santa? ":"yes"
}
a)
list
b)
string
c)
dictionart
d)
dictionary
15.

The output of the code above is

a)

Key Error

b)

4

c)

Math

16.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

17.

How do you create a variable with the numeric value 5?

a)

Both are correct

b)

x=5

c)

x=int(5)

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

What would be printed by the command

print('12-5')

a)

12-5

b)

'12-5'

c)

7

d)

'7'

20.

If num1 = 3

num2 = 4

then what will be the output of num1 ** num2

a)

3

b)

7

c)

12

d)

81

21.

In Python, 'Hello', is the same as "Hello"

a)

yes

b)

no

22.

Which one is NOT a legal variable name?

a)

my_var

b)

myvar

c)

_myvar

d)

my-var

23.

What is a correct syntax to output "Hello World" in Python?

a)

echo("Hello World")

b)

echo "Hello World"

c)

print("Hello World")

d)

PRINT("Hello World")

24.
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
25.

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

26.

The above program prints

a)

Numbers 1 to 10 in reverse order

b)

Numbers 1 to 11 in reverse order

c)

Numbers 1 to 10

d)

Numbers 1 to 11

27.

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

a)
b)
c)
d)
28.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

29.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
30.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)