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.
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.
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 a dir(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 be while (numguesses < maxguesses) and flag:
play_again()
is unnecessarily recursive.
s1 = secret[0] ; s2 = secret[1]
could be s1,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:
if (i%2 == 0):
evaluated = evaluated + s1
else:
evaluated = evaluated + s2
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