【发布时间】:2013-09-05 11:48:28
【问题描述】:
这是我的代码:
print "Note: Your file is available now."
viewYourFile = raw_input("\nDo you wish to view this file now? ")
if viewYourFile == 'Y' or 'y':
fo = open('messages.txt', 'r+')
#Read whole file into data
data = fo.read()
print data
# Close the file
fo.close()
elif viewYourFile == 'N' or 'n':
print "Thank you!"
else:
print "Didn't recognize user input"
当我输入“n”时,文本文件仍然打开。如果用户输入“N”或“n”,我希望脚本继续运行,而不会将文本打印到终端。
我看不出有什么明显的错误。有人可以再看看我吗?非常感谢。
【问题讨论】:
-
@BubbleMonster 如果你得到答案,请选择一个。
标签: python if-statement