Friday, March 27, 2020

number guess game using python

'''
 You decide you want to play a game where you are hiding
 a number from someone.  Store this number in a variable
 called 'answer'.  Another user provides a number called
 'guess'.  By comparing guess to answer, you inform the user
 if their guess is too high or too low.

 Fill in the conditionals below to inform the user about how
 their guess compares to the answer.
'''
answer = int(input("enter a number as ans"))#provide answer
guess =int(input("enter a number as guess")) #provide guess

if answer > guess :
    #provide conditional
    result = "Oops!  Your guess was too low."
elif answer < guess : #provide conditional
    result = "Oops!  Your guess was too high."
elif answer == guess : #provide conditional
    result = "Nice!  Your guess matched the answer!"

print(result)

output:
enter a number as ans56

enter a number as guess47
Oops!  Your guess was too low.

No comments:

Post a Comment

python class topic video