Created
December 11, 2015 20:45
09 Guessing Game One
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
May 9, 2018
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