mardi 7 novembre 2017

Why is my function running twice, while assigning an inputed value to the return?

I have a long complicated code(witch i have not put in), I have a function at the beginning that asks a question then sets the the answer to a variable. Then I return that variable.

I then use that answer to the variable later in the code, depending on what the person answered. For some reason, when the code receives that variable answer it uses an if then statement, to test what the answer was. However whatever I put in for the variable answer, the function plays itself over again for some reason twice, then it functions the way I want it to.

Does anyone have an answer as to why this is happening, here is a similar code, to what I am trying to achieve if a visual is needed.

def you ():
   gi=input("what up")
   return gi

result = you()
if result in ["Nothing much", "nothing much", "nothing"]:
   print("cool")
elif result in ["stuff"]:
   print("sounds good")

Aucun commentaire:

Enregistrer un commentaire