据我所知http://pastebin.com/mfJfp5sB我一次只能存储一个名字。我想知道如何创建一个输入所有姓名的字典,并检查之前是否输入了该人的姓名。
blue = "\033[94m"
name = input("What's your name?")
with open("name.txt") as openfile:
for line in openfile:
for part in line.split():
if name in part:
print(blue + "I remember you " + name + "!")
else:
print("Well Nice to meet you " + name + "!")
file = open("name.txt", "w")
file.write(name)
file.close()
答案 0 :(得分:0)
如果可以告诉我,请尝试以下操作:
name = input("What's your name?")
with open("name.txt", 'a') as openfile:
openfile.write(name)
with open("name.txt",'r+') as openfile:
for line in openfile:
for part in line.split():
if name in part:
print(blue + "I remember you " + name + "!")
else:
print("Well Nice to meet you " + name + "!")