user_num =9; #Initialize a random non-native number to be able to go to the core of the while loop
while (user_num >= 0): #After each user input, check if the input is a non-negative number
#If user input is a non-negative number, you end up here, inside the while loop
print("Body") #This is one of the statements. It prints "Body"
user_num = int(input()) #Acquire a new input from the user and store it in the variable user_num. At this point, the loop runs again using the new user input.
#If user input doesn't meet the while loop's condition, you end up here, outside the while loop
print('Done.')
2条答案
按热度按时间b4lqfgs41#
下面是一个解决方案,每行都有一些注解:
字符串
第一行
user_num = 9
作为用户的第一个输入。您希望这个数字满足while
循环的条件,以便它在其中执行语句。下面是一个很好的开始while循环的地方:https://www.w3schools.com/python/python_while_loops.asp
5m1hhzi42#
这是正确答案:
字符串