Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Checking Input Against a List

+2 votes
asked May 6, 2021 by TheMenard1 (190 points)
name = input("Name of patient: ")
birth_year = int(input("Birth year of patient: "))
age = 2021 - birth_year
previous_patients = ["John Smith", "Allen Mincer", "Ron Fritz"]
print("Patient " + name + " is " + str(age) + " years old")
if name == list(previous_patients):
    print("Registered")
else:
    print("New")

I want it to print out "Registered" if the name from the input matches a name in previous_patients

I've spent a couple of hours on it and can't figure it out, thanks.

1 Answer

0 votes
answered May 15, 2021 by xDELLx (10,500 points)
if name in  list(previous_patients):
    print("Registered")
else:
    print("New")


Change the == to in,& it will work !!

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...