Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Random Guessing Number
- def randomNumbers(debugMode="no"):
- from random import randint
- correct = randint(1,20)
- guesses = 0
- debugMode = debugMode.lower()
- print("I'm thinking of a number between 1 and 20.")
- print("You can type \"stop\" at any time to stop.")
- if debugMode == "true" or debugMode == "yes":
- print("The number is: " + str(correct))
- while True:
- print("Enter your guess.")
- while True:
- guess = input(">>> ")
- if guess.isdigit() == False and guess.lower() != "quit" and guess.lower() != "stop":
- print("Only enter (positive) numbers.")
- pass
- else:
- break
- if guess.lower() == "quit" or guess.lower() == "stop":
- print("Stopping...")
- break
- guess = int(guess)
- if guess == correct:
- guesses += 1
- if guesses == 1:
- print("You won in %s guess! Good job!" %guesses)
- elif guess > 1:
- print("You won in %s guesses! Good job!" %guesses)
- break
- elif guess > correct:
- print("Your guess is too high.")
- guesses += 1
- elif guess < correct:
- print("Your guess is too low.")
- guesses += 1
- else:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement