Вам необходимо определить свою функцию, прежде чем пытаться ее вызвать. Просто поставьте def option1(): #and all that code below it
над вашими заявлениями if.
Это также плохая практика бросить слишком много глобальных переменных. Вы не должны использовать так, как вы есть - вместо этого передайте его функции как параметр и позвольте функции работать в своей области. Вам нужно будет передать функции имя файла для использования, прежде чем он сможет использовать . Попробуйте вместо этого:
def option1(whattosaveinfile):
test = open("test.txt","a+") #probably better to use a with statement -- I'll comment below.
test.write(whattosaveinfile) #note that you use the parameter name, not the var you pass to it
print("Option 1 used")
test.close()
#that with statement works better for file-like objects because it automatically
#catches and handles any errors that occur, leaving you with a closed object.
#it's also a little prettier :) Use it like this:
#
# with open("test.txt","a+") as f:
# f.write(whattosaveinfile)
# print("Option 1 used")
#
#note that you didn't have to call f.close(), because the with block does that for you
#if you'd like to know more, look up the docs for contextlib
if menu == "1": #no reason to turn this to a string -- you've already defined it by such by enclosing it in quotes
savinginfile = raw_input("Please state your name: ")
option1(savinginfile) #putting the var in the parens will pass it to the function as a parameter.
elif menu == "2": #etc
#etc
#etc
Что не работает? Вы получаете код ошибки ?? Пожалуйста, дополните. – jramirez