每当我在 IDLE 环境中启动程序时,如何修复 Python 重新启动?
How to fix Python restarting whenever I start program on IDLE environment?
import random
winning_conditon = 0
no_of_guesses = 0
comp_guess = random.randint(1,100)
while (no_of_guesses == 11) or (winning_conditon == 1):
user_guess = int(input("What is your guess? "))
if user_guess < 1 or user_guess > 100:
print("Your number is invalid!")
elif comp_guess == user_guess:
print("Well Done!")
winning_condition = 1
elif comp_guess < user_guess:
print("Your number is too high!")
elif comp_guess > user_guess:
print("Your number is too low!")
no_of_guesses = no_of_guesses + 1
print(no_of_guesses)
print("You haven't guessed the right amount of times or u won.")
每当我启动 python IDLE(我使用的是 Portable Python 3.2.5.1 (http://portablepython.com/wiki/PortablePython3.2.5.1/))时,它会出现一条重启消息,然后显示一个“=”签署并且不继续该程序。你知道解决办法吗?
当我 运行 你的程序时,我得到这个输出:
Python 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
You haven't guessed the right amount of times or u won.
>>>
这很好,符合预期。
我会这样修改你的程序:
while not (no_of_guesses == 11 or winning_conditon == 1)
while not
相当于 until
.
import random
winning_conditon = 0
no_of_guesses = 0
comp_guess = random.randint(1,100)
while (no_of_guesses == 11) or (winning_conditon == 1):
user_guess = int(input("What is your guess? "))
if user_guess < 1 or user_guess > 100:
print("Your number is invalid!")
elif comp_guess == user_guess:
print("Well Done!")
winning_condition = 1
elif comp_guess < user_guess:
print("Your number is too high!")
elif comp_guess > user_guess:
print("Your number is too low!")
no_of_guesses = no_of_guesses + 1
print(no_of_guesses)
print("You haven't guessed the right amount of times or u won.")
每当我启动 python IDLE(我使用的是 Portable Python 3.2.5.1 (http://portablepython.com/wiki/PortablePython3.2.5.1/))时,它会出现一条重启消息,然后显示一个“=”签署并且不继续该程序。你知道解决办法吗?
当我 运行 你的程序时,我得到这个输出:
Python 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
You haven't guessed the right amount of times or u won.
>>>
这很好,符合预期。
我会这样修改你的程序:
while not (no_of_guesses == 11 or winning_conditon == 1)
while not
相当于 until
.