Question:
I am super new to coding and am coding for an assignment for school and am having trouble doing an if statement assuming that’s what I should even be using but I want to be able to ask a question and have an if statement decide if the input is yes or no so it would be like if variable = yes print(“blahblah”) I don’t know if that’s even the best way to go about doing this but I am having a lot of trouble with it. Any help would be wonderful
Repl link:
code snippet
1 Like
Hey there, we cannot help on any school assignments 
EDIT: just change if beverage == ("yes")
to if beverage == "yes":
sigh ok
1 Like
I’m not asking for you to do my assignment I’m just asking for some help with putting in an if statement i’m sure if my teacher was here she would help me.
Edit: oh, thanks
1 Like
That’s the parts thats easy but how could I make it do different things afterwards like print different strings depending on it being yes or no?
1 Like
Should it not be an if statement i’m serously not sure if this is even the easiest way to do it
1 Like
Hey there, try this:
functions = {}
drink = None
def wrapper(command: str):
global functions
def within_wrapper(func):
global functions
functions[command] = func
return within_wrapper
@wrapper("yes")
def yes_func():
global drink
drink = input("Hello! What drink would you like?")
@wrapper("no")
def no_func():
print("You chose no!")
def process_input(text: str, secondary_fall_back_text: str = ""):
current = input(text)
while True:
if (current in functions):
functions[current]()
break
else:
print("That is not a valid option. Please try again.")
current = input(secondary_fall_back_text)
process_input("Would you like a drink?")
1 Like
This is actually super helpful thank you!
You’re welcome! I try to help around here, and welcome to the community as @sonicx180 would say