当我在 Python 中运行以下程序时,该函数将变量带入,但完全跳过其余部分并重新显示程序的主菜单,而不做任何事情。另外,即使选择了第一个或第二个选项(不需要第三个变量),它也会跳过限定的“if”语句并询问所有变量。顺便说一句,这不应该是缩进错误,我只是缩进显示它是stackoverflow中的代码。
编辑:没关系。我让它工作。函数括号中的变量都必须相同。呃!捶着额头
option = 1
while option !=0:
print "\n\n\n************MENU************"
print "1. Counting"
print "2. Fibbonacci Sequence"
print "0. GET ME OUTTA HERE!"
print "*" * 28
option = input("Please make a selection: ") #counting submenu
if option == 1:
print "\n\n*******Counting Submenu*******"
print "1. Count up by one"
print "2. Count down by one"
print "3. Count up by different number"
print "4. Count down by different number"
print "*" * 28
countingSubmenu = input("Please make a selection: ")
x=0
y=0
z=0
q=0
def counting (x, y, z, countingSubmenu, q):
x = input("Please choose your starting number: ")
y = input("Please choose your ending number: ")
if countingSubmenu == 1:
for q in range (x, y+1, 1):
print q
elif countingSubmenu == 2:
for q in range (x, y, -1):
print q
elif countingSubmenu == 3:
z = input("Please choose an increment: ")
for q in range (x, y+1, z):
print q
else:
z = input("Please choose an increment: ")
for q in range (x, y, -z):
print q
return x, y, z, q
if countingSubmenu == 1:
counting(countingSubmenu, x, y, z, q)
if countingSubmenu == 2:
counting(countingSubmenu, x, y, z, q)
if countingSubmenu == 3:
counting(countingSubmenu, x, y, z, q)
if countingSubmenu == 4:
counting(countingSubmenu, x, y, z, q)