I'm pretty new to python and I'm trying to make a simple program where you have text menus and I have to use functions to do most of the work (to get used to using functions inside a program). So I'm trying to use a function in this program to get the first, second, and possibly a third number from the user. I need to be able to reuse this function so I can get said numbers from the user, but I'm having problems with only being able to use these variables within the function and nowhere else. Any suggestions will help! Here's the code:
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."
local variables. If you want variables to exist outside of the function, you need to declare them outside of the function.