【发布时间】:2018-07-27 04:31:13
【问题描述】:
我正在制作一个 Dichotomous Key 程序,它通过提问来确定所讨论的生物的名称。这是它现在的样子:
step = 0
yes = ["y", "yes"]
no = ["n", "no"]
while step == 0:
q1 = input("Are the wings covered by an exoskeleton? (Y/N) ")
q1 = q1.lower()
if q1 in yes:
step += 1
elif q1 in no:
step += 2
else:
print("Huh?")
我如何将 if 和 else 语句放入一个函数中,以便我可以在提出的每个问题中重复使用它并更改 step 变量?
-谢谢
【问题讨论】:
-
但是如何从函数中更改非局部变量?
标签: python-3.x function global-variables