[Python] Converting a for loop to a while loop ( with a range involved)

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    Converting this to a while loop:

    sum = 0
    for i in range (10,0,-1):
    sum = sum +1
    print(i,sum)


    I can get:

    i=1
    while i in range(10,0,-1):
    print(i)
    print(i, end=' ')
    i=i+1


    The hard part is the range numbers.

    (A for loop is a better solution than a while loop.)

    Continue reading...

Compartilhe esta Página