How to fix Python restarting whenever I start program on IDLE environment?

你说的曾经没有我的故事 提交于 2020-01-17 21:12:13

问题


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.")

Whenever I start python IDLE (i am using Portable Python 3.2.5.1 (http://portablepython.com/wiki/PortablePython3.2.5.1/)) it comes up with a restart message and then it displays an "=" sign and doesn't continue the program. Do you know a fix?


回答1:


When I run your program I get this output:

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.
>>> 

This is perfectly fine and expected.

I would modify your program this way:

while not (no_of_guesses == 11 or winning_conditon == 1)

while not would be the equivalent of until.



来源:https://stackoverflow.com/questions/32937854/how-to-fix-python-restarting-whenever-i-start-program-on-idle-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!