Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Python Online

from random import randint 
myNumber = randint(1, 100) 
guessNum = 0
numberGuessed = False
guess = 0

print ("I'm thinking of a number between 1 and 100...")
print ("Make a guess and I'll tell you whether the number is higher or lower")

while numberGuessed == False:
    guess = int(input("Enter your guess"))
    guessNum += 1
    if myNumber > guess:
        print ("Higher")
    elif myNumber < guess:
        print ("lower") 
    elif myNumber == guess:
        print ("Well done you've guessed the number in " + str(guessNum) + " guesses") 
        numberGuessed = True

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.