0% found this document useful (0 votes)
15 views

For Loop

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

For Loop

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. In programming, what is iteration?

a) The repetition of steps within a program


b) The order in which instructions are carried out
c) A decision point in a program
d) Testing a program to make sure it works

2. Why is iteration important?


a) It determines the order in which instructions are carried out
b) It allows code to be simplified by removing duplicated steps
c) It allows multiple paths through a program
d) It ensures the code works correctly

3. Which two statements are used to implement iteration?


a) IF and WHILE
b) ELSE and WHILE
c) FOR and WHILE
d) IF and ELSE

4. Which type of loop iterates until instructed otherwise?


a) FOR loop
b) A count-controlled loop
c) Repeat-once loop
d) WHILE loop

5. Which of the following symbols is used in Python to mean "Equal to"?


a) =
b) !=
c) ==
d) >=

6. Which of the following symbols is used in Python to mean "Not equal to"?
a) ==
b) !=
c) <>
d) ><

7. Which of the following symbols is used in Python to mean "Greater than or equal to"?
a) <=
b) >>
c) >=
d) =>
8. In a Python program, what would be the iteration variable (looping variable) in the FOR LOOP
code?

n=6

value=0

for n1 in range(1,50,3):

n=n+value

value=value+5

print(n)

a) n1
b) n
c) value
d) i

9. a=5
b=10

for c in range(5,100,5):

num=a+b

print(num)

a) 60
b) 100
c) 10
d) 20

10. In a Python program, what would be the increment value for the looping variable in the FOR
LOOP code?

n=7

n1=50

for a in range(15):

print(a)
a) 15
b) 7
c) 10
d) 1

11. In a Python program, what would be the increment value for the looping variable in the FOR
LOOP code?

f=100

t=0

s=5

for a in range(f,t,-s):

print(a)

a) 100
b) 1
c) 5
d) -5

12. In a Python program, how many outputs will occur for the snippet of code?

g=15

for a in range(0,g,3):

print(a)

a) 15
b) 3
c) 6
d) 5

13. What will print to the screen in this code?

t=0

for i in range(0,3):
for j in range(3,5):

t+=i-j

print(t)

a) 18
b) 25
c) 10
d) 15

14. t=0

for i in range(0,5):

t=i______

print(t)

Ans=6.0

a) (* 3 / 2)
b) (+ 1)
c) (/ 0.5)
d) (+ 3* (1/ 2))

15. What is the output?

for i in range(1, 6):

print(str(i) * i)

a) 1 2 3 4 5
b)

12

123

1234
12345

c)

22

333

4444

55555

d)
1

16. for i in range(0,10):

if i%3==0:

i=0

else:

i=1

print(i)

a) 1, 0, 1, 1, 0, 1, 1, 1, 1, 1
b) 0, 1, 1, 0, 1, 1, 0, 1, 1, 0
c) 0, 1, 1, 0, 1
d) 0, 1, 1, 0, 1, 1, 0, 1, 1, 0

You might also like