Sometimes when I run this in IDLE, the shell will only show
>>
However, when I close the window and kill the program, it’ll appear as normal for a split second before closing. Most of the time it will work though.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For your problem in IDLE, I’d try flushing the stdout regularly to see if it helps at all.
Some comments about your code follow:
About the use of global variables, for most cases, you can simply substitute their use by function arguments. When you (think you) need to modify a global variable, generally you’re choosing the wrong functions to write. As an example, there’s absolutely no need to set the guesses variable inside generate(), you can just do it in play().
instead of
allowed = ('0','1','2','3','4','5','6','7','8','9','0','+','*'),consider
import string ; allowed= list(string.digits+'+'+'*'). Do adir(string)in the interpreter for more useful variables there.there’s no need to evaluate equality of a boolean.
while (numguesses < maxguesses) and flag==True:should bewhile (numguesses < maxguesses) and flag:play_again()is unnecessarily recursive.s1 = secret[0] ; s2 = secret[1]could bes1,s2=secret[:2]for i in range(max): ; num = num + str(randint(0,9))could be rewritten as"".join([str(randint(0,9)) for i in range(max)]). Some people will argue the first is more readable, it’s up for you to decide.Finally this:
could be replaced simply by
evaluated= (evaluated+s1) if not(i%2) else (evaluated + s2).I think you don’t actually need the parenthesis, but they add readability, IMHO
Obviously there’s a lot more that could be said about the general structure of the code, I tried to focus on python language features you may not know at this point