lol, oh yeah, I guess I should check the input. Simple things like this bore me though, I actually (sadly), just created this so I could play some game while i was waiting for my lecture content to download :lol:
I like taking on challenges though. :)
edit: Alright, how does this look?
Code:
import random
# The number the user is trying to guess
x = int(random.uniform(1, 100))
# The user's guess for the current try
g = 0
# The number of tries taken to guess the number (counter)
numG = 0
while g != x:
# Check user input
valid = False
while(not valid):
try:
g = int(raw_input('Take a guess (1-100): '))
valid = True
except:
print('Please enter a valid integer.')
# Increment guess counter
numG += 1
# Check user's guess to tell them higher or lower
if g > x:
print('Your guess was too high! Guess lower.')
elif g < x:
print('Your guess was too low! Guess higher.')
# Game finished, user found the guess number
print('You finally guessed the number in ' + str(numG) + ' tries.')
raw_input()
I was running it outside of the interpreter, so the window would close, otherwise I wouldn't need that last raw_input() line.
edit: Just found out that the random.py module has a randint() function that I could have used instead, I think i'm okay with where this is at though, It's just going to be another code snippet of mine on my file storage to collect dust for a while now that It doesn't entertain me anymore :grin1: