【发布时间】:2013-12-11 18:16:13
【问题描述】:
我试图在 if 语句中调用函数,但它不起作用。这是我第一次尝试使用 Python。我究竟做错了什么?
#!/usr/bin/python
menu = raw_input ("Hello, please choose form following options (1,2,3) and press enter:\n"
"Option 1\n"
"Option 2\n"
"Option 3\n")
if menu == str("1"):
savinginfile = raw_input ("Please, state your name: ")
option1()
elif menu == str("2"):
print ("Option 2")
elif menu == str("3"):
print ("Option 3")
def option1():
test = open ("test.txt", "rw")
test.write(savinginfile)
print ("Option 1 used")
test.close()
【问题讨论】:
-
什么不起作用??你得到一个错误代码??请详细说明。
标签: python function if-statement