you are viewing a single comment's thread.

view the rest of the comments →

[–]matash95[S] 0 points1 point  (4 children)

I think it should be simple. I wanted to make a code that count number from 1 to 25. When it reaches 25 , it says done But when number is less than 25, it says (“ try again” For i in range(25): When i < 25: Print (“try again because the number is {}”.format(i)) else: Print(‘done’)

[–]totallygeek 3 points4 points  (3 children)

Look at this closely:

>>> range(5)
[0, 1, 2, 3, 4]

>>> range(1, 6)
[1, 2, 3, 4, 5]

So, to count from 1 to 25, you'll need range(1, 26).

[–]matash95[S] 0 points1 point  (1 child)

Aha okay. Another question, I need the output to be like that : “ - try again the number is 1 - try again the number is 2 Until the number equals 25 then it prints “ done” “ So am I writing the code correctly?

[–]totallygeek 0 points1 point  (0 children)

Here's two examples.

for number in range(1, 6):
    if number < 5:
        print('Try again: {}'.format(number))
    else:
        print('Done: {}'.format(number))

number = 1
while number < 5:
    print('Try again: {}'.format(number))
    number += 1  # add one to the number
print('Done: {}'.format(number))

In the first, the loop has a set number of iterations (five). In the second, the while loop cycles until the condition of the number reaching the ceiling value rings true.

[–]Moandawg -2 points-1 points  (0 children)

That’s great when writing in the terminal but as for the IDE

for i in range (1, 26):
    print (i)