所以我对 Python 和一般编程很陌生。我的问题是关于我在这里的 while 循环标志。这有效,但不像我认为的那样。我想我不理解某些东西,所以如果有人能够解释,那就太好了。
根据我的理解,只要满足我的一个条件,就应该立即跳出循环。因此,如果我输入“q”,它应该会中断并停止循环。但发生的情况是它不断循环,然后爆发。所以它通过最后一个提示并打印异常。
(Python 版本为 3.8.5)
# Statement that tells the user what we need.
print("Enter two numbers and I will tell you the sum of the numbers.")
# Lets the user know they can press 'q' to exit the program.
print("Press 'q' at anytime to exit.")
keep_going = True
# Loop to make the program keep going until its told to stop.
while keep_going:
# Prompt for user to input first number and store it in …Run Code Online (Sandbox Code Playgroud)