So I am trying to get my Ask_Number to cooperate with my guessing game. For some reason the game code wont reconize that the Response to the Ask_Number is an interger. I've tried to define response as well and that just ends up breaking the code in a different way. I am going insane with this stuff. Here is the code:
import sys
def ask_number(question, low, high):
"""Ask for a number from 1 to 100."""
response = int(input(question))
while response not in range(low, high):
ask_number("Try again. ", 1, 100)
break
else:
print(response)
return response
ask_number("Give me a number from 1-100: ", 1, 100)
print("\tWelcome to 'Guess My Number'!")
print("\nI'm thinking of a number between 1 and 100.")
print("Try to guess it in as few attempts as possible. OR ELSE!!!\n")
le_number = ask_number
guess = int(input("Take a Friggin Guess: "))
tries = 1
# guessing loop
while guess != le_number:
if guess > le_number:
print("Lower Idgit....")
else:
print("Higher Idgit...")
if tries > 5:
print("Too bad Idgit. You tried to many times and failed... What a shocker.")
print("The number was", le_number)
input("\n\nPress the enter key to exit Idgit")
sys.exit()
guess = int(input("Take a guess:"))
tries += 1
print("You guessed it! The number was", le_number)
print("And it only took you", tries, "tries!\n")
input("\n\nPress the enter key to exit Idgit")
If you guys could help me shed some light that would be great.