# # Radom guess game. By Sam DiBattista # my first Python app! 6/22/2017 # # note: For this version, the computer is playing against itself LOL. # the user input box was a bit odd and messed up the output flow. # line 23 should accept user input. # #need random for this to work import random # # the main method # def main(): rslt = random.randint(1,10) print("I'm thinking of a number between 1 and 10. Take a guess") done = False counter = 0 while not done: counter += 1 answer = random.randint(1,10) done = checkAnswer(rslt, answer) if counter == 5: done = True print("too many guesses. The answer was " + str(rslt)) # # function to check the answer. Returns true if the answer was good, # False otherwise # def checkAnswer(r, a): isDone = False if a == r: print("wow! " + str(a) + " You got it!") isDone = True elif a < r: print(str(a) + " is too low...") elif a > r: print(str(a) + " is too high...") return isDone # # Fire in the hole # main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question