1. Engineering
  2. Computer Science
  3. i 1 print quotusing the while loop quot while...

Question: i 1 print quotusing the while loop quot while...

Question details

i = 1
print ("Using the while loop: ")
while (i <= 280):
    print (i, end= " ")
    i += 31;
  
l = [i for i in range(1,281,31)]
print ("\nUsing the for loop with a list:")
for ele in l:
    print (ele, sep=", ", end = " ")

print ("\nUsing the for loop with range, three arguments: ")
for i in range(1,281,31):
    print (i, sep=", ", end = " ")

print ("\nUsing the for loop with range, one argument: ")
for i in range(281):
    if i % 31 == 1:
        print (i, end = " ")


how do i make the out put like this with a comma and space using str method and without using any additional variables in the code with the loops and you should not use the if statement in the implementation. Nor should you use a second while statement as a "hidden" if statement. :

Using the while loop:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Using the for loop with a list:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Using the for loop with range, three argument:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Using the for loop with range, one argument:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution