Skip to main content
Code Review

Return to Revisions

2 of 2
replaced http://stackoverflow.com/ with https://stackoverflow.com/

You have a function called input_guess(). That function inputs the guess, compares the guess, and plays the entire game. It should only input the guess. I would create a function to run the program, one to input the number, and one to do the comparison and output prompts about being too large or small. This way, only the function that plays the game needs to know the number of moves left. Once the number is correctly guessed, that function just returns to its caller, who can call it again if the user wants to play again. Also, try not to write functions this long.

As for your range100() and range1000() functions, I would combine those into one function like this:

def get_num(min, max):
 print "New game. Range is from " + min + " to " + max
 num = random.randrange(min, max + 1)
 return num

You can tell the user how many guesses they have left in the function that controls the game.

Finally, you should have the part of the program that always runs in an if __name__ == "__main__": block. This is for re-usability of your program, and you can read more about it here: What does if __name__ == "__main__": do?.

user34073
default

AltStyle によって変換されたページ (->オリジナル) /