Home > Software design >  python loop create i know its simple but I do not know what's wrong
python loop create i know its simple but I do not know what's wrong

Time:01-02

New to python trying to create while loop that print out 1 through 10 not just 10:

I=0
while I != 10:
    I  =1
print (I)

I do not know what I am doing wrong

CodePudding user response:

You have to put print() in the while loop:

I=0
while I != 10:
    I  =1
    print(I)

You can also use for loop:

for i in range(11):
    print(i)

CodePudding user response:

You need to put the print statement into the while loop.

I = 0
while I < 10:
    I  =1
    print(I)

This will print:

1
2
3
4
5
6
7
8
9
10

CodePudding user response:

Your code is actually right just you have to indent print() inside while loop

.....print(I)

I=0
while I != 10:
    I  =1
    print (I)

CodePudding user response:

'I = 0
while I != 10:
    I  =1
    print (I)'

you must line up print with I =1

  • Related