我該如何完成這項工作?我正在嘗試設置一個全局函數,以便稍後可以將其稱爲原始輸入,而不是在需要時調用原始輸入。設置函數調用python中的raw_input
我認爲我的精髓在於我需要的程度,但我很難理解如何格式化,或者甚至可能。
預先感謝您。
def choice_1():
choice_1 == raw_input("> ")
def choice_1a():
choice_1a = raw_input("> ")
def choice_1b():
choice_1b = raw_input("> ")
編輯:我不認爲我是在我的問題的目的很清楚。這裏是我正在處理的代碼的更新,也許這將清除一切。
print "You've arrived at your desk"
def choice_1(one):
choice_1a = raw_input("< ")
def choice_1a():
choice_1a = raw_input("> ")
def choice_1b():
choice_1b = raw_input("> ")
#Choice_1
print "What do you want to do?"
print "We can \n1. Read\n2. Draw\n3. Work on homework"
print choice_1
#choice 1 branch 1
if choice_1 == "1":
print "What book should we read today?"
print "We can read\n1. Tom Sawyer\n2. Quantum Physics \n3. Ray Bradbury"
print choice_1a
if choice_1a == "1":
print "Great choice!"
if choice_1a == "2":
print "Heavy stuff there."
if choice_1a == "3":
print "Entertaining author, that one there!"
else:
print "Let's go to the library, maybe they'll have that one."
#choice 1 branch 2
if choice_1 == "2":
print "What would you like to draw?"
print "We can draw a\n1. Tiger\n2. Fish\n3. Bear "
print choice_1b
if choice_1b == "1":
print "You drew a Tiger!"
if choice_1b == "2":
print "You drew a Fish!"
if choice_1b == "3":
print "You drew a Bear!"
else:
print "Time for some improvisation."
#choice 1 branch 3
if choice_1 == "3":
print ""
這是否清楚了一些混淆?
看起來你所缺少的是一些'return'語句。 – SethMMorton