Question: USE PYTHON3; DO NOT IMPORT ANY PACKAGES Please do all of question 3 (everything in the images) Here is the code format and the doctests

USE PYTHON3; DO NOT IMPORT ANY PACKAGES

Please do all of question 3 (everything in the images)

USE PYTHON3; DO NOT IMPORT ANY PACKAGES Please do all of question3 (everything in the images) Here is the code format and thedoctests given in the text editor: # Question 3 def q3_doctests(): """Q3 doctests go here. >>> h = Nonmetal("H") >>> h Nonmetal("H") >>>

Here is the code format and the doctests given in the text editor:

# Question 3 def q3_doctests(): """ Q3 doctests go here.

>>> h = Nonmetal("H") >>> h Nonmetal("H") >>> print(h) Nonmetal name: H, atomic number: 8, period: 2, group: 2 >>> h.get_mass() 66

>>> f = Metal("F") >>> f Metal("F") >>> print(f) Metal name: F, atomic number: 6, period: 1, group: 6 >>> f.get_mass() 78

>>> f == h False >>> f != h True >>> f > h True >>> f

>>> water = Compound("H2O1") >>> water Compound("H2O1") >>> print(water) H2O1 >>> water.elements {'H': 2, 'O': 1} >>> water.get_compound_mass() 255

>>> yummy_metal = Compound("U1") >>> dsc2 = Compound("D2S2C2") >>> dsc3 = Compound("D3S3C3") >>> cse = Compound("C7S8E9") >>> lava = Compound("H3O4") >>> obsidian = Compound("H5O5") >>> smelly_gas = Compound("H2")

>>> water == yummy_metal True >>> water >> water > dsc2 False >>> dsc2 + dsc3 Compound("C5D5S5") >>> water - smelly_gas Compound("O1") >>> dsc2 + cse Traceback (most recent call last): ... ValueError >>> water - lava Traceback (most recent call last): ... ValueError >>> water + lava == obsidian True """ return

LIST_METAL = "FKLPQRUVWXZ"

class Element: """ # TODO: add class docstring # """

def __init__(self, name): """ Constructor of Element Input validation is required Parameter: name (str): a single uppercase character from 'A' to 'Z' that represents the name of the element """ # YOUR CODE GOES HERE #

def get_mass(self): """ Returns atomic mass of this element This method is a placeholder to avoid style check errors in some editors or tools. You will overwrite this method in the subclasses. """ # DO NOT MODIFY # raise NotImplementedError("must be implemented in the subclasses")

def __eq__(self, other_elem): """ Returns True when two Elements are equal. Equality is determined by their atomic mass """ # YOUR CODE GOES HERE #

def __ne__(self, other_elem): """ Returns True when two Elements are not equal """ # YOUR CODE GOES HERE #

def __gt__(self, other_elem): """ Returns True when this Element is greater than the other """ # YOUR CODE GOES HERE #

def __ge__(self, other_elem): """ Returns True when this Element is greater than or equal to the other """ # YOUR CODE GOES HERE #

def __lt__(self, other_elem): """ Returns True when this Element is less than the other """ # YOUR CODE GOES HERE #

def __le__(self, other_elem): """ Returns True when this Element is less than or equal to the other """ # YOUR CODE GOES HERE #

def __repr__(self): """ Returns object representation of this Element """ # uncomment the following code # repr_form = "{0}(\"{1}\")" class_name = self.__class__.__name__ # repr_form = repr_form.format(...) return ...

class Nonmetal(Element): """ # TODO: add class docstring # """

def get_mass(self): """ Returns atomic mass of this Nonmetal element """ # YOUR CODE GOES HERE #

def __str__(self): """ Returns string representation of this Nonmetal element """ # uncomment the following code # str_form = \ # "Nonmetal name: {}, atomic number: {}, period: {}, group: {}" return ...

class Metal(Element): """ # TODO: add class docstring # """

def get_mass(self): """ Returns atomic mass of this Metal element """ # YOUR CODE GOES HERE #

def __str__(self): """ Returns string representation of this Metal element """ # uncomment the following code # str_form = "Metal name: {}, atomic number: {}, period: {}, group: {}" return ...

class Compound: """ # TODO: add class docstring # """

def __init__(self, name): """ Constructor of Compound Input validation is required Parameter: name (str): a string that represents the name of the compound """ # YOUR CODE GOES HERE #

def get_compound_mass(self): """ A simple getter of compound_mass """ # YOUR CODE GOES HERE #

def __eq__(self, other_comp): """ Returns True when two Compounds are equal. Equality is determined by their compound mass """ # YOUR CODE GOES HERE #

def __ne__(self, other_comp): """ Returns True when two Compounds are not equal """ # YOUR CODE GOES HERE #

def __gt__(self, other_comp): """ Returns True when this Compound is greater than the other """ # YOUR CODE GOES HERE #

def __ge__(self, other_comp): """ Returns True when this Compound is greater than or equal to the other """ # YOUR CODE GOES HERE #

def __lt__(self, other_comp): """ Returns True when this Compound is less than the other """ # YOUR CODE GOES HERE #

def __le__(self, other_comp): """ Returns True when this Compound is less than or equal to the other """ # YOUR CODE GOES HERE #

def __add__(self, other_comp): """ Synthesize a new Compound by adding this Compound with another Exception: ValueError will be raised if the product is invalid """ # YOUR CODE GOES HERE #

def __sub__(self, other_comp): """ Decompose this Compound by subtracting another from it. A new product is returned after decomposition Exception: ValueError will be raised if the product is invalid """ # YOUR CODE GOES HERE #

def __str__(self): """ Returns string representation of this Compound """ # YOUR CODE GOES HERE #

def __repr__(self): """ Returns object representation of this Compound """ # uncomment the following code # repr_form = "{0}(\"{1}\")" class_name = self.__class__.__name__ # repr_form = repr_form.format(...) return ...

Question 3: Marina has discovered 26 new chemical elements on Kerbin, a planet located somewhere in outer space. She decided to name these chemical elements with the English alphabet from 'A' to 'Z' (all capital letters), and drew out the following periodic table: 1(Group) 2 3 4 5 6 1(Period) A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 2. G, 7 H, 8 I, 9 ], 10 K, 11 L, 12 3 M, 13 N, 14 0, 15 P, 16 Q, 17 R, 18 4 S, 19 T, 20 U, 21 V, 22 W, 23 X, 24 Y, 25 Z, 26 Each chemical element belongs to a specific group and a specific period, and is either a Metal element (colored in BLUE) or a Non-metal element (colored in GREEN). In the periodic table, each element symbol is followed by an Atomic Number, which uniquely identifies its position in the table. For example, Element 'F' is a Metal element with Atomic Number 6, located at Period 1 Group 6. Part 0. Doctest Requirements All doctests go into 93_doctests(). For this question, initialize at least three instances for each concrete class (Metal, Nonmetal, and Compound). For each instance, follow the examples and create a set of tests on its constructor, get_mass() / get_compound_mass(), string and object representation. For comparison, add, and subtract functions, make sure your tests cover each operator (>,=, H505 Z9U8 + U1D3 => D30929 (ordered by elements' alphabetical order) H201 - H2 => 01 ('H' is reduced to O so it is removed from product name) P3Q4 + P6Q6 => raise ValueError( because 'P9Q10' does not exist P304 - P5Q5 => raise ValueError() because the numbers cannot go negative Notes: If other_comp has an element that self doesn't have, you should raise ValueError(), as you can assume self contains o atoms of that element. We won't test the case where a compound is subtracted from itself, which will basically result in a compound with an empty name. You can handle this case according to your own implementation. Submission By the end of this homework, you should have submitted the homework via Gradescope. You may submit more than once before the deadline; only the final submission will be graded. Question 3: Marina has discovered 26 new chemical elements on Kerbin, a planet located somewhere in outer space. She decided to name these chemical elements with the English alphabet from 'A' to 'Z' (all capital letters), and drew out the following periodic table: 1(Group) 2 3 4 5 6 1(Period) A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 2. G, 7 H, 8 I, 9 ], 10 K, 11 L, 12 3 M, 13 N, 14 0, 15 P, 16 Q, 17 R, 18 4 S, 19 T, 20 U, 21 V, 22 W, 23 X, 24 Y, 25 Z, 26 Each chemical element belongs to a specific group and a specific period, and is either a Metal element (colored in BLUE) or a Non-metal element (colored in GREEN). In the periodic table, each element symbol is followed by an Atomic Number, which uniquely identifies its position in the table. For example, Element 'F' is a Metal element with Atomic Number 6, located at Period 1 Group 6. Part 0. Doctest Requirements All doctests go into 93_doctests(). For this question, initialize at least three instances for each concrete class (Metal, Nonmetal, and Compound). For each instance, follow the examples and create a set of tests on its constructor, get_mass() / get_compound_mass(), string and object representation. For comparison, add, and subtract functions, make sure your tests cover each operator (>,=, H505 Z9U8 + U1D3 => D30929 (ordered by elements' alphabetical order) H201 - H2 => 01 ('H' is reduced to O so it is removed from product name) P3Q4 + P6Q6 => raise ValueError( because 'P9Q10' does not exist P304 - P5Q5 => raise ValueError() because the numbers cannot go negative Notes: If other_comp has an element that self doesn't have, you should raise ValueError(), as you can assume self contains o atoms of that element. We won't test the case where a compound is subtracted from itself, which will basically result in a compound with an empty name. You can handle this case according to your own implementation. Submission By the end of this homework, you should have submitted the homework via Gradescope. You may submit more than once before the deadline; only the final submission will be graded

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!