Python Forum

Full Version: A text-based game [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am making a text-based game and I am trying to run this code but the last two lines don't work and any number including 1 2 and 3 are printing enter 1 2 or 3. Please help me with this I am kind of new to python.

the code:
num = input('''-Write a number between 1 to 3 to ask the parallel question. Don't forget to click enter after you enter the number!-.
        1. Why are we going there?
        2. Can I just go back home?
        3. I am done\n''')
elif int(num) != 1 or int(num) != 2 or int(num) != 3:
    print('enter 1 2 or 3')
    exit()
this code will produce SyntaxError, because there is elif without if

Error:
File "***", line ** elif int(num) != 1 or int(num) != 2 or int(num) != 3: ^ SyntaxError: invalid syntax
Then, even if you fix it, this condition int(num) != 1 or int(num) != 2 or int(num) != 3: is always true, because you use or
(Apr-20-2021, 12:29 PM)buran Wrote: [ -> ]this code will produce SyntaxError, because there is elif without if

Error:
File "***", line ** elif int(num) != 1 or int(num) != 2 or int(num) != 3: ^ SyntaxError: invalid syntax
Then, even if you fix it, this condition int(num) != 1 or int(num) != 2 or int(num) != 3: is always true, because you use or

ok, I changed it to if but do you have any idea on how to make the condition not always true?
And, not or. Every number is eihter not 1 or not 2

But not in is better.
if num not in ('1', '2', '3')
or
if num not in '123':
Except that will also accept 12, 23 and 123
(Apr-20-2021, 01:56 PM)deanhystad Wrote: [ -> ]Except that will also accept 12, 23 and 123
Good catch