Anvit Garg Anvit Garg - 7 months ago 19
Python Question

Program Returning nothing

I saw this Flowchart and decided to make a program out of it. The problem is, it only returns "Go Outside" if I enter "no" the first time. All others return "None". Im using Python 2.7

def waitawhile():
print "Wait a while"
rain2 = raw_input("Is it still raining?")
if rain2.lower() == "no":
return "Go Outside"
elif rain2.lower() == "yes":
waitawhile()
def Raining():
print "Is it raining?"
rain = raw_input()
if rain.lower() == "no":
return "Go Outside"
elif rain.lower() == "yes":
print "Have Umbrella?"
umbrella = raw_input()
if umbrella.lower == "yes":
return "Go Outside"
elif umbrella.lower() == "no":
waitawhile()
print Raining()

Answer

The problem is with your calls to waitawhile (from both Raining and from waitawhile itself). After calling it, you're discarding the return value and returning nothing. To fix it, change the calls from:

waitawhile()

to:

return waitawhile()

Make sure that, for both functions, there is no way to reach the end of the function without executing a return statement.

Comments