Computer Science
Write the output of the following:
for j in range(10, 6, -2):
print(j*2)
Python
Python Control Flow
4 Likes
Answer
20
16
Working
The range(10, 6, -2)
function creates a range starting from 10 and decrementing by 2 until it reaches 6 (but does not include 6), resulting in the sequence [10, 8]. The for j in range(10, 6, -2):
statement sets up a for loop that iterates over each element in the generated sequence [10, 8]. During each iteration of the loop, the print(j*2)
statement prints the value of j
multiplied by 2.
Answered By
1 Like
Related Questions
Write the output of the following:
for i in '123': print("CPU", i)
Write the output of the following:
for i in [100, 200, 300]: print(i)
Write the output of the following:
for x in range(1, 6): for y in range(1, x+1): print (x, ' ', y)
Write the output of the following:
for x in range(10, 20): if (x == 15): break print(x)