Last answered:

11 Nov 2022

Posted on:

10 Nov 2022

0

when the user input -1 , not end , why this is happened?

user_input= int (input('enter your eage.-1 is end '))
ages=[]
while user_input > 0:
    ages.append(user_input)
    print(int(input('enter the next age')))
print('the ages are ', ages)
1 answers ( 0 marked as helpful)
Instructor
Posted on:

11 Nov 2022

1

Hey Roqia,

Thank you for reaching out!

Please, study the change in line 5:
image.png
In your version of the code, line 5 prints out the message 'enter the next age' but doesn't change the value of variable user_input. Therefore, when you repeat the while-loop again, user_input would not be changed to -1 which it needs to in order to exit the loop.

Hope this helps!

Kind regards,
365 Hristina

Submit an answer