Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def generateRandomNumber():
- return random.randint(1, 100)
- def askUserForNumber(message = "Guess the number: "):
- userNumber = int(input(message))
- return userNumber
- def checkUserNumber(userNumber, randomNumber):
- if userNumber > randomNumber:
- return "Too High"
- elif userNumber < randomNumber:
- return "Too Low"
- else:
- return "Congratulations!"
- def main():
- userCongratulated = False
- letsStart = True
- while userCongratulated or letsStart:
- userNumberOfGuesses = 0
- randomNumber = generateRandomNumber()
- # print ("for testing purposes, random number:", randomNumber )
- userNumber = askUserForNumber()
- userNumberOfGuesses += 1
- message = checkUserNumber(userNumber ,randomNumber)
- while message != "Congratulations!":
- print(message)
- userNumber = askUserForNumber("Try again ")
- userNumberOfGuesses = userNumberOfGuesses + 1
- message = checkUserNumber( userNumber , randomNumber )
- print()
- print(message, "it took you", userNumberOfGuesses,\
- "goes to guess correctly")
- userCongratulated = True
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement