在"删除"之后没有执行代码变量在下面的代码中。请让我知道出了什么问题。
known_users = ["Kumar", "Raavi", "Raj", "Rahul"]
while True:
print("my name is Sachin")
name = input("What is your name?").strip().capitalize()
if name in known_users:
print("hello{}!" .format(name))
remove = input("Would you like to be removed? (Y/N)").lower()
if remove=="y": #this code block is not getting executed..
known_users.remove(name)
print(known_users)
else:
print("Hmm, i dont think we have meet yet ")
add_name=input("Would you like me to add you in the list?").lower()
if add_name=="y":
known_users.append(name)
答案 0 :(得分:0)
我99%肯定,因为你的情况并非如此,你的阻止不会被执行。首先......您要求输入Y
或N
,但请检查小写y
。字符串区分大小写,y
不等于Y
。因此,您可以尝试检查它们或执行以下操作:
if remove.lower() == "y"
要调试你的代码,我会添加这样的临时块(在bugfix之后将其删除):
if remove == "y":
known_users.remove(name)
print(known_users)
else:
print(remove)