I bring this code review plea over from suggestions from SO. I've made the suggested edits from that thread, except I kept one sys.exit()
call because I was having trouble exiting otherwise. Overall, the code works as desired, and I'm looking for advice on how I can make it even cleaner.
import time
import sys
done = "I'm tired of you. Goodbye."
rainedOut = "Sorry, rain foiled your plans :("
dontUnderstand = "I'm sorry, I don't understand."
def good_weather():
"""Imagine a world where every 5 seconds it rains (good_weather = False),
then is sunny again (good_weather = True). This function should return
whether good_weather is True or False at the time it's called.
"""
return (time.time() % 10) <= 5
def start():
entries = 0
while entries < 4:
choice = raw_input("Hello! What do you want to do right now? Options: 1) Sleep, 2) Work, 3) Enjoy the great outdoors: ")
if choice == "1":
print "We are such stuff as dreams are made on, and our little life is rounded with a sleep. - Shakespeare, The Tempest"
elif choice == "2":
work()
elif choice == "3":
outdoors()
else:
print dontUnderstand
entries += 1
print done
def work():
entries = 0
entries2 = 0
while entries < 4:
choice = raw_input("Would you prefer sedentary office work or manual labor in the elements?: ")
if "office" in choice:
print "The brain is a wonderful organ; it starts working the moment you get up in the morning and does not stop until you get into the office. -Robert Frost"
start()
elif "manual" in choice:
sunny = good_weather()
if sunny == True:
print "A hand that's dirty with honest labor is fit to shake with any neighbor. -Proverb"
start()
else:
if entries2 < 3:
print rainedOut
entries2 += 1
continue #restart loop
else:
print "You should probably just give up now."
start()
else:
print dontUnderstand
entries += 1
print done
sys.exit()
def outdoors():
sunny = good_weather()
if sunny == True:
print "Adopt the pose of nature; her secret is patience. -Ralph Waldo Emerson"
start()
else:
print rainedOut
start()
start()