Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am really confused on how to code this program so can someone please help me asap! You may not use any libraries/modules except that

I am really confused on how to code this program so can someone please help me asap!
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
You may not use any libraries/modules except that you may find pprint (pretty print) useful for displaying lists of lists. Your instructor will demonstrate how to use pprint. 1) [25 marks] Write a function named open_file that takes the name of a csv file (including '.csv) as a string as its parameter. This function must use 'try' and 'except' to open the file safely. If the file cannot be opened or does not exist, the function must display File does not exist. It will then extract the information, creating a list of lists with each of the inner lists being data from a row with the exception that the first row (column titles) of data is not included. For 'YearDiscovered' that is 'Ancient', use the value 0 . This list of lists must be returned. For example: print (data) [[1, 'H', 'Hydrogen', '1.00794(4) ', 'gas', 14, 20, 8.99e-05, 1766],[2, 'He', 'Helium', '4.002602(2)', 'gas', 0, 4, 0.0001785, 1868], [3, 'Li', 'Lithium', '6.941(2)', 'solid', 454, 1615,0.535,1817],[4, 'Be', 'Beryllium', '9.012182(3)', 'solid', 1560, 2743, 1.848, 1798], ... 2) [10 marks] The data in all but the AtomicMass column is in usable form and, therefore, requires no modification. The AtomicMass data is in the form of strings with most strings of the form '1.00794(4)'. The number in the brackets may indicate that this is weight of the most stable or common isotope. The brackets and the number they contain needs to be removed (or not included) and the rest of the string converted to a float. Some atomic masses are strings of the form '[209]', the brackets may indicate that this is an estimate. The square brackets must be removed (or not included) and the rest of the string converted to a float. Write a function called clean_atomic_mass that takes the list of lists created in open_file and modifies it by converting each atomic mass string into a float (without the round brackets and the number they contain or without the square brackets). This function returns the list of lists. For example: clean_atomic_mass (data) print (data) [[1, 'H', 'Hydrogen', 1.00794, 'gas', 14, 20, 8.99e-05, 1766], [2, 'He', 'Helium', 4.002602, 'gas', 0, 4, 0.0001785,1868],[3, 'Li', 'Lithium', 6.941, 'solid', 454, 1615, 0.535, 1817], [4, 'Be', 'Beryllium', 9.012182, 'solid', 1560, 2743, 1.848, 1798], [10 marks] Write a function called discovery_date that takes the list of lists, an integer representing a start date, and an integer representing an end date as its parameters. This function must call validate_range using the start date and end date. If the start date and end date are not integers or if the start date is after the end date, the function will display "Years must integers or the start must be before the end" and 2 return None. This function will return a list of tuples (element and their date of discovery) of all elements discovered between the start and end dates. The start and end dates must be included. The returned list must be sorted according to year of discovery - oldest first, elements discovered in the same year must be sorted alphabetically (see example below). NB - this list may be empty. For example: discovery_date (data, 1905, 1941) [(1907, 'Lutetium'), (1913, 'Protactinium'), (1923, 'Hafnium'), (1925, 'Rhenium'), (1937, 'Technetium'), (1939, 'Francium'), (1940, 'Astatine'), (1940, 'Neptunium'), (1940, 'Plutonium')] discovery_date (data, 0, 1715) [(0, 'Aluminum'), (0, 'Antimony'), (0, 'Arsenic' ),(0, 'Bismuth'), (0, 'Calcium'), (0, 'Carbon'), (0, 'Chromium'), (0, 'Cobalt'), (0, 'Copper'), (0, 'Gold'), (0, 'Iron'), (0, 'Lead'), (0, 'Mercury'), (0, 'Platinum'), (0, 'Silver'), (0, 'Sulfur'), (0, 'Tin'), (1669, 'Phosphorus'), (1670, 'Fluorine')] 4) [5 marks] Write a function named validate_zange that takes two values (representing a start year and an end year) as its parameters. This function will return False if both of the parameters are not integers or if the start year is after the end year (both years may be the same), otherwise it returns True. For example: validate_range ('start', 'end') False validate_range ('start', 1885) False validate_range (1603, 'end') False validate_range (1900,1885) False validate_range (1900,1931) True 5) [10 marks] Write a function named standard state that takes the list of lists and a string representing a state ('solid', 'liquid', 'gas') as its parameter. This function calls validate_state and retums True or False if the parameter is not a string or if it is a string but not 'solid', "liquid', or 'gas'. If validate_state returns True, it returns a list of tuples each containing the name of the element and the year of its discovery. This list must be sorted alphabetically according to the element name (A>Z). For example: standard_state (data, '1iquid') [('Bromine', 1826), ('Mercury', 0)] 6) [5 marks] Write a function named validate sta te that takes a value representing a state ('solid', 'liquid', 'gas') as its parameter. This function returns False if the parameter is not a string or it is a string but not 'solid', 'liquid', or 'gas', otherwise this function returns True. This function must be case insensitive for its parameter. For example: validate_state (3.14159) False validate_state ('gaz') False validate_state('gas') True validate_state ('liquid') True validate_state('solid') True 7) [10 marks] Write a function named find_names that takes the list of lists and a string as its parameter. This function returns a list of tuples, each tuple containing the name of an element starting with the string and that element's symbol. This list must be sorted alphabetically according to the element name (A>Z). If the list is empty, display an error message. This function must be case insensitive for its string parameter. For example: find_names (data, 'm') [('Magnesium', 'Mg'), ('Manganese', 'Mn'), ('Meitnerium', 'Mt'), ('Mendelevium', 'Md'), ('Mercury', 'Hg'), ('Molybdenum', 'Mo'), ('Moscovium', 'Mc')] find_names (data, ' Q ') Ther are no elements that start with "Q" find names (data, 12) There are no elements with 12 find_names (data, "ar") [('Argon', 'Ar'), ('Arsenic', 'As')] 8) [25 marks] Write a function named ma in that takes no parameters and returns None. This function must demonstrate all of the functions. This function is allowed to be considerably longer than 20 lines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago