Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python-random-rangeLoop

Total questions: 21

Worksheet time: 21mins

Name
Class
Date
1.

What does the random module in python do i.e. import random

a)

Pauses the program for a few seconds

b)

Generates random numbers

2.

Which programming construct is used in specifically in 'For' and 'While' loops?

a)

Sequence

b)

Selection

c)

Iteration

3.

Which of the following is correct?

a)

if colour==blue

b)

if colour=blue:

c)

if colour=="blue":

d)

if color=blue

4.

if you type print("4"+"9") what result would you get

a)

49

b)

13

c)

error

d)

0

5.

To include the use of functions which are present in the random library, we must use the option:

a)

import random

b)

random.h

c)

import.random

d)

random.random

6.

The output of the above Python code is either 1 or 2.

a)

True

b)

False

c)

error

7.

What will be the output of above given code

a)

Error

b)

Either 10.4, 56.99 or 76

c)

Any number other than 10.4, 56.99 and 76

d)

56.99 only

8.

What will be the output of the following Python function (random module has already been imported)?


random.choice('sun')

a)

sun

b)

u

c)

either s,u or n

d)

error

9.
a)
b)
c)
d)

1,2,3,4

10.

#What is the output?

a)

1,2,3,4,5

b)

0,1,2,3,4

c)

1,2,3,4

d)

5,4,3,2,1

11.

#How many hallos will be printed?

a)

5

b)

None

c)

4

d)

6

12.

#What is the output?

a)

a, b, c, d, e

b)

a, a, a, a, a

c)

0,1,2,3,4

d)

e, d, c, b, a

13.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
14.
What is iteration known as?
a)
Looping
b)
Crashing
c)
Repeating
15.
What will be printed after running this FOR loop:

for number in range(6):
 
    print(number)
a)
The number 6 
b)
The numbers 0 - 5
c)
The number 5
d)
The numbers 1 - 6
16.

Which of the following programs prints ten lines?

a)

for i in range(10):

print("hi")

b)

for i = 1 to 10:

print("hi")

c)

for i in 1 - 10:

print("hi")

d)

for i from 0 to 9:

print("hi")

17.

What would be the output of the following code:

for i in range(3):

print(i)

a)

1 2 3

b)

i i i i

c)

i i i

d)

0 1 2

18.

What would be the output of the following code:

for i in range(3):

print(5)

a)

0 1 2

b)

3 3 3 3 3

c)

5 5 5

d)

0 1 2 3 4

19.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

20.

For i in range(6):

print('Happy Python')

How many times Happy Python will be printed?

a)

4

b)

5

c)

6

d)

7

21.

What are the syntax errors in this code?

a)

:

b)

Not indented

c)

Both options