wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python set 4

Total questions: 44

Worksheet time: 1hrs 6mins

Name
Class
Date
1.

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

2.

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

a)
b)
c)
d)
3.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

4.

A while loop equivalent of the for loop above is

a)
b)
c)
d)
5.

What does this program print

a)

2 + 2 = 4

4 + 4 = 8

8 + 8 = 16

16 + 16 = 32

32 + 32 = 64

b)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

c)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

2 + 10 = 12

d)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

e)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

6.

Match the following for the values each range( ) function will generate.

a)

a-1, b-2, c-4, d-3, e-5

b)

a-2, b-5, c-4, d-1, e-3

c)

a-3, b-2, c-5, d-1, e-4

d)

None

7.

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

8.

How many times the following loop will execute:

i = 1

while True:

print(i)

i += 2

a)

0

b)

2,4,6,8,..................

c)

1,3,5,7,9,.............

d)

1,2,4,6,8......................

9.

for loop in python works on:

a)

1.range

b)

2.iteration

c)

3.Both of the above

d)

4.None of the above

10.

i = 1

while True:

if i%7 == 0:

break

print(i)

i += 1

a)

123456

b)

1234567

c)

error

d)

none

11.

i = 1

while False:

if i%2 == 0:

break

print(i)

i += 2

a)

1

b)

1357......

c)

1234......

d)

none of the mentioned

12.

x = 123

for i in x:

print(i)

a)

1 2 3

b)

123

c)

error

d)

none of the above

13.

for i in range(10):

if i == 5:

break

else:

print(i)

else:

print("Here")

a)

01234 Here

b)

012345 Here

c)

01234

d)

12345

14.

string = "my name is x"

for i in string:

print (i, end=", ")

a)

m, y, , n, a, m, e, , i, s, , x,

b)

m, y, , n, a, m, e, , i, s, , x

c)

my, name, is, x,

d)

error

15.

x = 'abcd'

for i in range(len(x)):

print(i.upper())

a)

a b c d

b)

0 1 2 3

c)

error

d)

1 2 3 4

16.

x = 'abcd'

for i in range(len(x)):

x = 'a'

print(x)

a)

a

b)

abcd abcd abcd

c)

a a a a

d)

none

17.

Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?

a)

print('Hello World')

b)

print("Hello World")

c)

print('Hello World")

d)

print(""'Hello World'"")

18.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

19.

data = "No Way!" The expression len(data) evaluates to:

a)

7

b)

9

c)

8

d)

6

20.

Which operator returns True if target string is somewhere in the search string; otherwise it returns False.

a)

==

b)

!=

c)

in

d)

is

21.

What syntax can you use to insert a line break between strings so that they appear over multiple lines?

a)

\l

b)

/

c)

\\n

d)

\n

22.

What will the output be from the following code?

print("Hello world!" * 2)

a)

TypeError

b)

Hello world world!

c)

Hello world!Hello world!

d)

Hello world! * 2

23.

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!

24.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

25.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

26.
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
27.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
28.

You have the following dictionary definition:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

29.

Which operator checks if a value is equal to another value?

a)

+

b)

=

c)

==

d)

!=

30.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
31.
The number or word we give to a variable
a)
Value
b)
Bug
c)
Information
d)
Text
32.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
33.
What would print (10 + 16) produce?
a)
20
b)
22
c)
24
d)
26
34.

Which is the Python logo?

a)
b)
c)
d)
35.

What is an input?

a)

A command that allows us to ask the user to enter some data.

b)

To plug in something.

c)

Data displayed on a screen.

d)

A function

36.

What is an output?

a)

A piece of data that is shown on the screen.

b)

Data that the user enters

c)

An output

d)

A orange

37.

x = 5

y = 6

print("x*y")


The code above displays the following:

a)

11

b)

x*y

c)

Syntax Error

d)

30

38.

Choose the correct operators used in python:


divide, multiply, add, subtract

a)

/, *, +, -

b)

div, mul, +, -

c)

\, x, +, -

d)

~, *, +, -

39.

Which operator checks if a value is not equal to another value?

a)

==

b)

+=

c)

!=

d)

=

40.

A data type that can have one of two values: True or False

a)

boolean

b)

variable

c)

modulo

d)

interpreter

41.
Which of the following is a float?
a)
new_var = 1234
b)
new_var = True
c)
new_var = 1.234
d)
new_var = "True"
42.
Which of the following is not a string?
a)
new_var = "True"
b)
new_var = "3123"
c)
new_var = "3.123"
d)
new_var = False
43.
What will the following code do? 
name = "Bob"
if name == "Bob": 
     print ("Hello " + name) 
else:  
     print ("I dont know you")
a)
prints bob
b)
prints Hello Bob
c)
nothing syntax error
d)
prints I don't know you
44.

Integers are ____________ and floats are _____________

a)

whole numbers and exponents

b)

powers and fractions

c)

fractions and whole numbers

d)

whole numbers and decimal numbers