vendredi 10 juillet 2020

If statement does not run even after user input

optionone = 0    #DEFINING BOTH VARIABLES 
optiontwo = 0

class first_day_morning:    #WORKING 
    optionone = input("It is now morning, would you like to (1) Leave your house or (2) Do some chores? ")


def first_choice(optionone):        #NOT WORKING DOING ELSE COMMAND FOR 1 INPUT
     if optionone == 1: 
         time.sleep(1)
        print('')
        print("You have chosen to get out of the house for once")
    elif optionone == 2: 
        time.sleep(1)
        print('')
        print("DO LATER")
    else: 
        time.sleep(1)
        print('')
        print("please choose a valid option")

first_choice(int(input()))

I am trying to make it so that the user input decides the outcome of the if statement, if user inputs 1, then something happens, if user inputs 2 then something else happens, if user inputs anything else, than the if statement runs again as only 1 or 2 are valid inputs. However, the problem is that no matter what the user inputs, the if statement does not run, and no error is shown either. I tried a try/except in case an error just isn't showing for some reason (try except ValueError:) and nothing seemed to work I have also tried to specify the input as str, int, float, no specification, raw_input etc. and nothing really works, can someone help?

ps. I am using Visual Studio Code

As you can see, the if statement does not run as no error is shown even after user input.

Aucun commentaire:

Enregistrer un commentaire