0
I want to prepare a program taking 2 numerical inputs from the user for comparison and then showing the result.
But at the end of this sequence I want the program to ask the user whether they want to do another comparison and the code loops back. How can I do this?
2 Réponses
+ 4
make the input and comparison a function and after calling it once ask for another user input like “do you want to do it again? y or n“. if y, call the function, if n, quit the program. if you put that in a while loop, it'll ask repeatedly until the user says n.
don't forget to handle other inputs too, in case the user tries to be funny or just hits the wrong key.
0
while Treu: #so it will loop forever
your code
#ask if they want to stop
a = input('do you want to stop[y/n]')
# if they want to stop (n) it breaks
if a == 'n'
break