I am trying to make my function take an name from the user which would check if the name is in a whitelist before executing a function that prints draws out information from a pre-defined list of the same name but the entered input is being processed as a string by the function instead of the name of the list. How do I get it to take in the input as the name of the list?
hydrogen = ["Hydrogen", "H", "1", "1.0"]
helium = ["Helium", "He", "2", "4.0"]
universe = ["hydrogen", "helium"]
elementname_print = "Element Name: "
elementsymbol_print = "Element Symbol: "
atomicnumber_print = "Atomic Number: "
relativeatomicmass_print = "Relative Atomic Mass: "
def printelement(element):
print(f" \n-------------------------")
print(elementname_print + element[0])
print(elementsymbol_print + element[1])
print(atomicnumber_print + element[2])
print(relativeatomicmass_print + element[3])
print("-------------------------")
userinput = input("-->")
if userinput in universe:
printelement(userinput)
else:
print("Sorry that element cannot be found.")
Result:
--> hydrogen
Element Name: h
Element Symbol: y
Atomic Number: d
Relative Atomic Mass: r