0
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.

2
  • 1
    What is the class for? Commented Jul 11, 2020 at 4:25
  • Because earlier i used a func, all variables I used were local to that function, so I decided to use a class with __init__() but neither did that work, so I just left the class there from earlier, I did not think that would change anything Commented Jul 11, 2020 at 4:36

3 Answers 3

1

When the program runs, the class body will be evaluated, meaning the input("It is now morning, would you like to (1) Leave your house or (2) Do some chores? ") will prompt for input. That value will then be kept in first_day_morning.optionone, however first_choice's optionone is different. It is equal to the parameter supplied on the final line, int(input()), which will silently prompt for another input, and then convert it to an integer. From what I think you're trying to achieve, I'd recommend you remove the class and change the final line to:

first_choice(int(input("It is now morning, would you like to (1) Leave your house or (2) Do some chores? ")))
Sign up to request clarification or add additional context in comments.

Comments

0
def first_choice():
    print('')
    print("You have chosen to get out of the house for once")

def second_choice():
    print('')
    print("DO LATER")

def third_choice():
    print('')
    print("please choose a valid option")


while True:

    print("""Select a choice""")

    c = int(input('enter your choice:'))
    if c == 1:
        first_choice()
    elif c == 2:
        second_choice()
    elif c == 3:
        third_choice()
    elif c == 4:
        break

Comments

0

i dont really understand what u r trying to acomplish here, but the code works for me, some tips from a beginer: -you define optiontwo and never use it -you you are filling optionone with input inside a class, dont know why, cause is never used not sure what do u want, but try this:

import time

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("It is now morning, would you like to (1) Leave your house or (2) Do some chores? ")))

although, test it in console, not sure about vscode but running inside sublime does not ask for input

1 Comment

I use optiontwo later in the code, not right now, and thank you, I will try in console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.