# Define an empty List called InfoDb
InfoDb = []
# InfoDB is a data structure with expected Keys and Values
# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
"Elemental_Symbol": "F",
"Element": "Fluorine",
"Molar_Mass": "18.998",
"Atomic_Number": "9",
"Year_Found": "1886",
"Natural_Isotopic_Mass": ["19"]
})
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"Elemental_Symbol": "Cl",
"Element": "Chlorine",
"Molar_Mass": "35.45",
"Atomic_Number": "17",
"Year_Found": "1774",
"Natural_Isotopic_Mass": ["35", "37"]
})
# Append to List a 3rd Dictionary of key/values
InfoDb.append({
"Elemental_Symbol": "Br",
"Element": "Bromine",
"Molar_Mass": "79.904",
"Atomic_Number": "35",
"Year_Found": "1826",
"Natural_Isotopic_Mass": ["79", "81"]
})
# Append to List a 4th Dictionary of key/values
InfoDb.append({
"Elemental_Symbol": "I",
"Element": "Iodine",
"Molar_Mass": "126.90",
"Atomic_Number": "53",
"Year_Found": "1811",
"Natural_Isotopic_Mass": ["127", "129"]
})
# Append to List a 5th Dictionary of key/values
InfoDb.append({
"Elemental_Symbol": "At",
"Element": "Astatine",
"Molar_Mass": "210",
"Atomic_Number": "85",
"Year_Found": "1940",
"Natural_Isotopic_Mass": []
})
# While loop so as long as user says yes to adding an element, it'll append the list
while (input("Would you like to add another element to this list of elements? Yes or no?").lower() == "yes"):
# Input to append list with
Add_Elemental_Symbol = input("What is the symbol of the element you would like to add?")
Add_Element = input("What is the name of the element you would like to add?")
Add_Molar_Mass = input("What is the molar mass of the element you would like to add?")
Add_Atomic_Number = input("What is the atomic number of the element you would like to add?")
Add_Year_Found = input("In what year was the element you would like to add discovered?")
Add_Natural_Isotopic_Mass = input("What are the masses of the natural isotopes of the element you would like to add?")
# Append list
InfoDb.append({
"Elemental_Symbol": Add_Elemental_Symbol,
"Element": Add_Element,
"Molar_Mass": Add_Molar_Mass,
"Atomic_Number": Add_Atomic_Number,
"Year_Found": Add_Year_Found,
"Natural_Isotopic_Mass": Add_Natural_Isotopic_Mass.split()
})
# Print in either forward or reverse order depending on user input
order = input("Would you like to format the list in forward or reverse order?")
if order.lower() == "forward" or order.lower() == "forward order":
for i in range(len(InfoDb)):
print("Entry: " + str(i+1))
print("\tElemental Symbol: " + InfoDb[i]["Elemental_Symbol"])
print("\tElement: " + InfoDb[i]["Element"])
print("\tMolar Mass: " + InfoDb[i]["Molar_Mass"])
print("\tAtomic Number: " + InfoDb[i]["Atomic_Number"])
print("\tYear Found: " + InfoDb[i]["Year_Found"])
print("\tMass of Natural Isotopes: " + str(InfoDb[i]["Natural_Isotopic_Mass"]))
elif order.lower() == "reverse" or order.lower() == "reverse order":
for i in range(len(InfoDb)):
reverseindex = len(InfoDb) - i - 1
print("Entry: " + str(i+1))
print("\tElemental Symbol: " + InfoDb[reverseindex]["Elemental_Symbol"])
print("\tElement: " + InfoDb[reverseindex]["Element"])
print("\tMolar Mass: " + InfoDb[reverseindex]["Molar_Mass"])
print("\tAtomic Number: " + InfoDb[reverseindex]["Atomic_Number"])
print("\tYear Found: " + InfoDb[reverseindex]["Year_Found"])
print("\tMass of Natural Isotopes: " + str(InfoDb[reverseindex]["Natural_Isotopic_Mass"]))
else:
print("You did not enter a valid response, please try again!")