我正在尝试将用户提供的单词(例如"orange"
)与我在文本文件中的单词列表进行比较,如下所示:
菜单.txt
apple
banana
orange
grape
mango
用户输入来自easygui.enterbox
. 我从来没有得到我期望的结果,因为它很难比较字符串。这是我的代码。
import easygui
count = 0
dish = easygui.enterbox("enter your favourite dish:")
with open("menu.txt") as f:
content = f.readlines()
for item1 in content:
if item1 == dish :
easygui.msgbox("order taken.thankyou")
count = count + 1
continue
if count == 0 :
easygui.msgbox("plz order some other item")