Using Python... You have to do your chemistry homework, but you hate looking up
ID: 3564252 • Letter: U
Question
Using Python...
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!"
Explanation / Answer
atom=raw_input('Enter The Name of Element Name : ')
if (atom=="hydrogen"):
atom_weight=1.008
print "Atomic Weight of ",atom," is : ",atom_weight
elif(atom=="helium"):
atom_weight=4.0026
print "Atomic Weight of ",atom," is : ",atom_weight
elif(atom=="lithium"):
atom_weight=6.94
print "Atomic Weight of ",atom," is : ",atom_weight
else:
print("Sorry, I don't recognize that element!")
Output 1
Enter The Name of Element Name : lithium
Atomic Weight of lithium is : 6.94
Output 2
Enter The Name of Element Name : carbon
Sorry, I don't recognize that element!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.