import random print("\tWelcome to Guess the number") print("\nI'm thinking of a number between 1 and 100") print("Try to guess it in as few attempts as possible.\n") # Set variables guess = int(input("Take a guess: ")) tries =1 number = random.randint(1,100) # Guessing loop while guess != number and tries < 10: if guess > number: print ('Lower...') else: guess < number print ('Higher....') guess = int(input("Take a guess: ")) tries +=1 if tries >= 10: print ('You have run out of tries') else: guess == number print ('You guessed correct, the number was ', number,' it took you ', tries, ' goes to get it right') ("\n\nPress the enter key to exit")
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