I have this prompt:
You have to do your chemistry homework, but you hate looking up elements on the periodic table! Write a program that takes the name of an element (as a string, independent of case) from standard input and prints a double representing its atomic weight to standard output. Only implement the program for the first three elements, hydrogren, helium, and lithium, which have the respective atomic weights 1.008, 4.0026, and 6.94. If anything else is given as input, print the statement "Sorry, I don't recognize that element!"
I wrote a code but keep getting wrong results. It doesn't matter what I type, it always comes up wrong. The standard output keeps stating "Enter element name:" along with atomic weight number
Here's what I wrote:
hydrogen = 1.008
helium = 4.0026
lithium = 6.94
atomic_weight = input("Enter element name:").lower()
if atomic_weight == hydrogen:
print(hydrogen)
elif atomic_weight == helium:
print(helium)
elif atomic_weight == lithium:
print(lithium)
else:
print("Sorry, I don't recognize that element!")
Updated code
hydrogen = 1.008
helium = 4.0026
lithium = 6.94
element_name = input("Enter element name:").lower()
if element_name == hydrogen:
print(hydrogen)
elif element_name == helium:
print(helium)
elif element_name == lithium:
print(lithium)
else:
print("Sorry, I don't recognize that element!")