Getting Q as input
Quit = int(input('Press Q to Quit')
You request Q as input, but only accept int . So remove the int part:
Quit = input('Press Q to Quit')
Now Quit will be what the user enters, so let instead of True check "Q":
if Quit == "Q":
Instead of sys.exit(0) you can just end your scan with break or just return if you are in a function.
In addition, I do not recommend the name "Quit" for a variable that simply stores user input, as this will end up confusing.
And remember that indentation is important in Python, so it should be:
if run == False: choice = input('Press Q to Quit') if choice == "Q":
It can only be a copy / paste error.
Indentation and Syntax
I fixed the indentation and removed the extraneous code (since you are duplicating the outer loop and some of the print statements) and got this:
print('How old do you thing Fred the Chicken is?') number = 17 run = True while run: guess = int(input('Enter What You Think His Age Is....t')) if guess == number: print('Yes :D That is his age...') run = False elif guess < number: print('No, Guess a little higher...') elif guess > number: print('No, Guess a little lower....') if run == False: print('Game Over') choice = input('Press Q to Quit') if choice == 'q' break
This gave me a syntax error:
blong @ubuntu: ~ $ python3 chicken.py
File chicken.py, line 23
if choice == 'q'
^
Syntax Error: invalid syntax
So, Python says that something is wrong after the if . If you look at the other if , you will notice that at the end of this one is missing : so change it to:
if choice == 'q':
So, with this change, the program starts up and seems to do what you want.
Some suggestions
Your instructions say, โPress Q to exit,โ but you actually accept โqโ to exit. You can accept both. Python has an operator called or , which takes two truth values โโ( True or False ) and returns True if either of them is True (in fact, it is more than True and False , see the documentation if you are interested).
Examples:
>> True or True True >>> True or False True >>> False or True True >>> False or False False
So, we can set Q or q with if choice == "Q" or choice == "q":
Another option is to convert the string to lowercase and check only Q using if choice.lower() == "q": If choice was Q, he would first convert it to q (using .lower() ), then perform a comparison.
Your number is always 17. Python has a random.randint () function that will give you a random number that can make the game more fun. For example, this would make the chicken age between 5 and 20 (inclusive):
number = random.randint(5, 20)