Which of the following function returns a sequence 0, 1, 2, 3?
Practice for loop Questions – Which of the following function returns a sequence 0, 1, 2, 3?
Practice for loop Questions – Which of the following function returns a sequence 0, 1, 2, 3?
Practice for loop Questions – How many times is the print statement executed?
for i in range(10):
for j in range(i):
print(i * j)
Practice for loop Questions – Which of the following loops prints “Welcome to Python” 10 times?
A:
for count in range(1, 10):
print(“Welcome to Python”)
B:
for count in range(0, 10):
print(“Welcome to Python”)
C:
for count in range(1, 11):
print(“Welcome to Python”)
D:
for count in range(1, 12):
print(“Welcome to Python”)
Practice for loop Questions – Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + … + 99/100?
A:
sum = 0
for i in range(1, 99):
sum += i / (i + 1)
print(“Sum is”, sum)
B:
sum = 0
for i in range(1, 100):
sum += i / (i + 1)
print(“Sum is”, sum)
C:
sum = 0
for i in range(1.0, 99.0):
sum += i / (i + 1)
print(“Sum is”, sum)
D:
sum = 0
for i in range(1.0, 100.0):
sum += i / (i + 1)
print(“Sum is”, sum)
Practice for loop Questions – Given the following four patterns,
Pattern A Pattern B Pattern C Pattern D
1 1 2 3 4 5 6 1 1 2 3 4 5 6
1 2 1 2 3 4 5 2 1 1 2 3 4 5
1 2 3 1 2 3 4 3 2 1 1 2 3 4
1 2 3 4 1 2 3 4 3 2 1 1 2 3
1 2 3 4 5 1 2 5 4 3 2 1 1 2
1 2 3 4 5 6 1 6 5 4 3 2 1 1
Which of the pattern is produced by the following code?
for i in range(1, 6 + 1):
for j in range(6, 0, –1):
print(j if j <= i else” “, end = ” “)
print()
Practice for loop Questions – What is the number of iterations in the following loop:
for i in range(1, n + 1):
# iteration