I want to renew the "namelist" for each iteration and use "if" to compare "name" against "namelist". The first iteration will always replace the content of "namelist" because the "namelist" at the first iteration is empty. For iteration number x, I therefore want "name" to be compared with the list's content from the previous iteration, ie x - 1. I do not want to append "name" to "namelist" but replace the entire content so the comparison is always between "name" and the latest version of "namelist". The "#-line" in the code shows where I think the operator should be.
def loop():
namelist = []
a = 1
while a < 5:
name = input("enter your name")
if name != namelist:
# operator that replaces the contents of "name list" with "name"
else:
continue
a += 1
loop()
Aucun commentaire:
Enregistrer un commentaire