NEW
Font size
WorksheetsLOOPS
Total questions: 10
Worksheet time: 5mins
Which is the correct output for :
for i in range(1,10):
print(i)
1,2,3,4,5,6,7,8,9
1,2,3,4,5,6,7,8,9,10
0,1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6,7,8
What is a loop?
A loop without conditions
A loop with an if statement
In computer programming, a loop is an order of instructions that repeats for many times
Which is not a valid Python loop?
for loop
while loop
iter loop
for num in [11, 9, 88, 10, 90, 3, 19]:
print(num)
if(num==88):
print("The number 88 is found")
print("Terminating the loop")
break
Output?
11
9
88
The number 88 is found
Terminating the loop
11
88
9
The number 88 is found
Terminating the loop
9
88
10
The number 88 is found
Terminating the loop
88
10
90
The number 88 is found
Terminating the loop
Each repetition is called ... of loop
counter
iteration
number of loops
starting value
What Is Range() Function?
The first is the iterable object such as a list, tuple or a string.
The “iter” represents the iterating variable.
The “sequence” may refer to any of the following Python objects such as a list, a tuple or a string.
The range() function can produce an integer sequence at runtime.
What Is A Python For Loop?
The range() function can produce an integer sequence at runtime.
The “sequence” may refer to any of the following Python objects such as a list, a tuple or a string.
A for loop in Python requires at least two variables to work.
for a in range(4):
print(a)
OUTPUT?
0
1
2
3
1
2
3
0
2
4
0
1
2
3
4
numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple
count_odd = 0
count_even = 0
for x in numbers:
if x % 2:
count_odd+=1
else:
count_even+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)
Number of even numbers:5
Number of odd numbers: 4
Number of even numbers:4
Number of odd numbers: 5
Number of even numbers:3
Number of odd numbers: 4
Number of even numbers:5
Number of odd numbers: 3
for i in range(1,100):
if i%2!=0:
print(i)
Output?
prints all even numbers
prints all odd numbers
prints all even,odd numbers
