Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am stuck on this lab assignment so can someonw plz help asap! You may not use any libraries/modules except that you may find pprint

image text in transcribed I am stuck on this lab assignment so can someonw plz help asap!
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) [11, '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 fioat (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) lf1, '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', 'Beryl1iun', 9.012182, 'solid', 1560, 2743, 1.848, 17981. 3) [10 marks] Write a function called di scovery 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 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'), (1937, 'Technetium'), (1939, 'Francium'), (1925, 'Rhenium')', (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, 'platinun'), (0, 'Silver'), (0, 'Sulfur'), (0, 'Tin'), (1669, 'Phosphorus'), (1670, 'Fluorine') ] discovery date (data, 1958, 1958) There were no elements discovered in the range 1958 to 1958 4) [5 marks] Write a function named vali date range 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 (bo fi y years may be the same), otherwise it returns True. For example: 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 returns True or False if the parameter is not a string or if it is a string but not 'solid', Tiquid', 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 (AZ). For example: standard_state (data, '1iquid') [('Bromine', 1826), ('Mercury', 0)] 6) [5 marks] Write a function named validate state that takes a value representing a state ('solid', "liquid', 'gas') as its parameter. This function returns Fal se 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 (AZ). 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'), ('Moscovi um', 'Mc')) find names (data, ' Q ') There 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 main 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 with AI-Powered 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

Students also viewed these Databases questions