Question: Problem: I have supplied code to read in a comma - separated value ( csv ) file that contains several pieces of data for each
Problem: I have supplied code to read in a commaseparated value csv file that contains several pieces of data for each element in the periodic table. The Summary of assignment
Write the program using only functions we have covered in class ie those that are part of the core Python library no addional libraries may be used. If you
aren't sure if a function you would like to use is OK contact me
Tips and additional things to keep in mind as you complete the assignment
Hint: the user entry part of the program would be a good place to use a while loop.
Try to define your variables near the top of your program and give them meaningful names using snake case of course
Complete each part of your program and demonstrate that it "works" before proceeding to the next piece. This will make it easier to understand any
issues you run into as you go along. It will also ensure that if you get stuck or run out of time you will be able to submit something that is a working part
of the program. For example, complete the dictionary and test it using print statements before moving on You will then have some confidence that any
issues you encounter downstream are less likely to be related to the dictionary.
Start as soon as you can on this one. There are a number of parts to it where none of them are particularly difficult or complicated but trying to quickly
turn something out next Friday would be challenging.
Enter element name and one of name protons, mass, density, mp bp separated by a space: li bp filename "PeriodicTable.csv
tablelines tablefile openfilenamer
for line in tablefile:
tablelines.appendline
header tablelines # column headers from csv file
elementdata tablelines: # data for all elements organized as one element per line
data in the table are arranged such that each row contains the data, separated by commas, corresponding to that element. The variable header in the code
below contains a comma separated list of the column headers for the table data each column corresponds to a piece of the element data, density, for
example The variable element data contains the rows of element data decribed above.
Read the instructions for the assignment carefully!
Write a program that does the following:
Create a Python dictionary that contains the element symbols as the dictionary keys and the value corresponding to each key is a list containing, in this
exact order. the element symbol properly capitalized eg He; the element name in all lower case eg helium; the number of protons; the atomic
mass; density; melting point; and boiling point so the list will contain seven pieces of element data If there is no data in the table corresponding to
any one of the seven pieces of data for an element the dictionary should contain the string "unknown" for that piece of data. You must ensure that the
items are of the correct type as well for example name values are strings, proton numbers are ints and densities are floats. I will be checking this as part
of my testing.
Request the user to enter the element symbol in lower case, followed by a space, followed by one of the following words: name, protons, mass, density,
bp which correspond to the last six pieces of element data in the list within your dictionary. Your program will need to use the header variable to
determine how to locate the items in the element data rows of elementdata. If the user enters invalid values either the element symbol or data word
you must return an error message and then prompt the user again. Repeat until they enter a valid input.
Based on what the user inputs, your program will print out the element symbol, properly capitalized, followed by the element data entered by the user.
The output must be carefully formatted exactly like the cell below for neon where in this case the user entered: ne name where there is a single space
before and after the output values and the and characters enclose the output as shown in the cell below this one.
included summary and example code in the photos
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
