这是我的代码:
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”,我希望脚本继续运行而不将文本打印到终端中。
我看不出我做错了什么明显的事情。有人可以再看看我吗?非常感谢。