我对python还很陌生,我正在尝试制作一个简单的程序,其中有文本菜单,我必须使用函数来完成大部分工作(以习惯于在程序中使用函数)。所以我尝试在这个程序中使用一个函数,从用户那里得到第一个,第二个,可能还有第三个数字。我需要能够重用这个函数,这样我就可以从用户那里得到所说的数字,但是我有一个问题,就是只能在函数中使用这些变量,而不能在其他地方使用这些变量。任何建议都会有帮助!代码如下:option = 1
while option !=0:
print "\n\n\n************MENU************"
print "1. Counting by one"
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"
countingSubmenu = input("Please make a selection: ")
def getNum():
firstNum = input("Please state what number to start at: ")
secondNum = input("Please state what number to end at: ")
if countingSubmenu == 3 or countingSubmenu == 4:
thirdNum = input("Please state what increment you would want to go up by: ")
if option == 1:
getNum()
for x in range(firstNum, secondNum+1):
print x
print "End of test."