Search code examples
pythonfunction

Python print both def instead of one, i want it to either answer to yes or no


Hello im new to Python it's my first time trying to write something, i want this to be able to either answer to yes or no but when i type either yes or no it always print:

nice

oh no

def yes1(): 
   print("nice")

def no1():
   print("oh no")

input("Welcome are you ok ?\nyes/no:")

yes = yes1
yes1()

no = no1
no1()```

Solution

  • I highly recommend you have a look at basic programming tutorials. if/elif/else statement knowledge is invaluable.

    But as a temporary solution while you learn, have a look at the following and see if it makes sense to you:

    def yes1(): 
       print("nice")
    
    def no1():
       print("oh no")
    
    user_input = input("Welcome are you ok ?\nyes/no:")
    
    if user_input.lower()=="yes":
        yes1()
    elif user_input.lower()=="no":
        no1()