Why cant i print inside a function with a If statement?


#1

hello

why cant i print inside a function with a If statement ?..
this is my function :

happy= raw_input ("are you happy with that ? : ")
def happy_or_not(happy) :
  if happy=="yes" : 
      print "great"
  elif  happy=="no":
    print "why"

thanks!


#2

you can.

But functions only execute when called, so if you want to see result, you will need to call the function


#3

thanks for your answer,
could you tell me how i call a function ? here for this example ?
thanks


#4

you have two happy variable:

# global happy variable containing user input
happy= raw_input ("are you happy with that ? : ")
# local variable happy as function parameter
def happy_or_not(happy) :

i wouldn’t give the same name to both the global variable and the parameter.

well, given your function has a parameter, you need to pass an argument at function call, which i assume is happy (the global variable that is).


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.