【发布时间】:2012-07-30 22:12:29
【问题描述】:
while True:
x = raw_input()
if x =="personal information":
print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN: , SS:'
elif x =="journal":
name_of_file = raw_input("What is the name of the file: ")
completeName = "C:\\python\\" + name_of_file + ".txt"
file1 = open(completeName , "w")
toFile = raw_input("Write what you want into the field")
file1.write(toFile)
file1.close()
else:
break
脚本不断给我一个错误,说 break 在循环之外是缩进错误吗?
【问题讨论】:
-
你必须修复你的缩进
-
另外,你可能会后悔没有把 open(completeName, 'w') 放在 try/catch OSError...特别是如果'completeName'是根据用户输入计算的...(只是说'):)
标签: python loops if-statement break