facebook twitter pinterest google plus Youtube
www.TestsTestsTests.com
For Loop Python Test – Free Online Python Computer Programming Test – Python For Loops Test

For Loop Python Test
Computer Programming Languages – Python
Free Online Python For Loops Test

* Range() Function Python
* Python For Loop Syntax and Structure
* Loop Body
* Loop Through Strings
* Nested Loop Python

Test yourself on Python For Loops – Loops allow execution of a fragment of code numerous times. Definite loops have a counter to store the number of iterations, others are called conditional loops and their execution depends on some preset conditions.

***GO TO THE TEST ANSWER EXPLANATIONS PAGE




10 Question Multiple Choice Quiz with Answers and Answer Explanations

1) Which of the following pieces of code defines a list of all the numbers from 1 to 10?
a) range (1,10)
b) range (1,11)
c) range (0,9)+1
d) range (1,2,3,4,5,6,7,8,9,10)


2) Which of the following sequences would be generated bt the given line of code?
range (10, 0, -5)
a) 10 5
b) -5 0 5 10
c) 0 5 10
d) 10 5 0 -5


3) What is the correct term to call one execution of a loop?
a) Counter
b) Function
c) Run
d) Iteration


4) What is the value of variable sum after execution of the following code?
sum=10
for number in range (1, 10, 2):    
   
sum += number
a) 19
b) 35
c) 23
d) 45


5) There are a number of apples on the counter, lying as a pyramid. Calculate the total number of apples in 5 rows using a loop. What is the correct line of code to put inside the loop?
Python Test For Loop Question 5
total=0
for row in range (1, 5): 

print(total)

a) total += 1
b) total += apples
c) total += row
d) total += range


6) Single-celled amoeba divides itself into two cells every 3 hours. What is the correct piece of code to create a loop to calculate the number of amoebas in 24 hours?
Python Test For Loop Question 6

amoebas=1

   
amoebas *=2
print(amoebas)

a) for hour in range (1, 25, 3):
b) for hour in range (3, 25, 3):
c) for hour in range (3, 24, 3):
d) for hour in range (1, 8, 3):


7) There are steps of bricks with the following structure.
Python Test For Loop Question 7
What is the correct piece of code to print out the pattern of the steps?
##
####
######
########
a) for row in range (5):
               print (“##”*row)

b) for row in range (5):    
                print (“#”*row)

c) for bricks in range (2,8):
                print (“#”*bricks)

d) for row in range (4):
                print (“##”*row)



8) What is the result of the execution of the following code?
for letter in “word”:
     
print(letter, end=””)
a) letter
b)

l
e
t
t
e
r


c)

w
o
r
d


d) word


9) What is the result of the execution of the following code?
for x in range (2):
     for y in range (2):
            print(x, y, sep=”)
a)

00
01
10
11


b)

0 0 sep
0 1 sep
1 0 sep
1 1 sep


c)

00 01 10 11

d) The compile command.

01
10
00
11



10) Each pixel in the monitor displays colors by combination of values red, green and blue, which can take values from 0 to 255. What parameters should be put inside the range function to produce the following RGB codes (colors are presented for reference only)?
Python Test For Loop Question 10
for red in range ( ):
    
 for green in range ( ):
         
 for blue in range ( ):
             
  print(red, green, blue, sep=”, “)

Pyth0n for Loop Test image 2 Question 10

a) 0, 0, 0
b) 0, 256, 255
c) 255
d) 255, 255, 255




* More from Tests Tests Tests.com