Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2015 20:45
09 Guessing Game One
import random
# Awroken
MINIMUM = 1
MAXIMUM = 9
NUMBER = random.randint(MINIMUM, MAXIMUM)
GUESS = None
ANOTHER = None
TRY = 0
RUNNING = True
print "Alright..."
while RUNNING:
GUESS = raw_input("What is your lucky number? ")
if int(GUESS) < NUMBER:
print "Wrong, too low."
elif int(GUESS) > NUMBER:
print "Wrong, too high."
elif GUESS.lower() == "exit":
print "Better luck next time."
elif int(GUESS) == NUMBER:
print "Yes, that's the one, %s." % str(NUMBER)
if TRY < 2:
print "Impressive, only %s tries." % str(TRY)
elif TRY > 2 and TRY < 10:
print "Pretty good, %s tries." % str(TRY)
else:
print "Bad, %s tries." % str(TRY)
RUNNING = False
TRY += 1
@ebashirli
Copy link


num = random.randint(1, 9)
count = 1
guess = input('Guess the number in my mind '\
                      'between 1 and 9, including or type "exit" to finish: ')
while True:
    if guess.lower() == 'exit':
        break
    try:
        guessInt = int(guess)
        if guessInt < 1 or guessInt > 10:
            guess = input('Plase type a number between 1 and 9, ' \
                          'including or type "exit" to finish: ')
        elif guessInt == num:
            print('You did. It took you ' + str(count) + ' tries.')
            guess = input('Let\'s try again: ')
        elif guessInt < num:
            guess = input('Too low. Try again: ')
        else:
            guess = input('Too high. Try again: ')
        count += 1
    except:
        guess = input('Plase type a number between 1 and 9, ' \
                      'including or type "exit" to finish2: ')

@Raj39120
Copy link

def game():
def actual_game():
import random
print("This is a guessing game. If you want to exit the game at any time, type exit surrounded by quotes.")
print("The computer has generate a random integer between 1 and 9 and including 1 and 9.")
number = random.randint(1, 9)
guess = 0
count = 0

    while guess != number and guess != "exit":
        guess = input("Enter you guess of what the number is over here: ")

        if type(guess) == float:
            print("Please enter an integer. You should've put " + str(int(guess)) + " and (not " + str(guess) + ")")
            return

        if guess == "exit":
            break

        guess = int(guess)
        count += 1

        if guess < number:
            print("Too low!")
        elif guess > number:
            print("Too high!")
        else:
            print("You got it!")
            print("And it only took you", count, "tries!")
            actual_game()
actual_game()

game()

this another version, although your code is much better and a bit more user friendly and checks to see if it is an integer but yours is better since it makes it an integer automatically saving the user time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment