Write a loop to print the numbers: 11, 21, …51 using python
Answers
Answered by
8
In this series, we start off with 11 and then keep adding 10 to the each number and print it until we get 51.
_____________________________________________
CODE:
series = [11]
while series[-1] != 51:
series.append(series[-1] + 10 )
print(*[x for x in series],sep = ',')
_______________________________________________
We said while the last number of the list is not equal to 51, add 10 to the last number of the list.
'-1' index is for the last number.
So, if the last number of the list is 51, it breaks off and prints the elements in the list separated by a comma.
________________________________________________
OUTPUT:
11,21,31,41,51
______________________________________________
Similar questions