This is a simple guessing game where you are prompted for a minimum and maximum value, then you must guess the number the computer chooses! This is the first program I have written so any and all suggestions are welcome.
def guessinggame():
print "Welcome to the Guessing Game!."
while True:
try:
numrange1 = int(raw_input("What is the minimum number you want?: "))
break
except ValueError:
print "This must be an integer!"
while True:
try:
numrange2 = int(raw_input("What is the maximum number you want?: "))
break
except ValueError:
print "This must be an integer!"
rnumber = random.randint(numrange1, numrange2)
i = 0
while True:
x = int(raw_input("What is your guess?: "))
if rnumber > x:
print "Low!"
i = i + 1
elif rnumber < x:
print "High!"
i = i + 1
elif rnumber == x:
print "Correct!"
i = i + 1
print i
break
again = raw_input("Would you like to play again? (y/n): ")
if again == 'y':
guessinggame()
guessinggame()