# Please find the updated codes:
# olympicmedal.py
class OlympicMedal:
def __init__(self, the_event, the_medal_type=0):
self.event = the_event
if the_medal_type < 1 or the_medal_type > 3:
self.medal_type = 0
else:
self.medal_type = the_medal_type
def __str__(self):
types = ["unknown", "gold", "silver", "bronze"]
return f"{self.event} :: {types[self.medal_type]}"
def __repr__(self):
return str(self)
test1.py from olympicmedal import OlympicMedal medal1 = OlympicMedal("Women's Archery", 2) medal2 = OlympicMedal("Women's Badmiton", 1) medal3 = OlympicMedal("Men's 200 Meter Dash") medal4 = OlympicMedal("Men's Marathon", 7) medals = [medal1, medal2, medal3, medal4] print(medals) print(medals[2]) print(medals[1].event) print(medals[3].medal_type)test2.py:
from olympicmedal import OlympicMedal
import unittest
class TestStringMethods(unittest.TestCase):
def test_1(self):
m1 = OlympicMedal("Women's Badmiton", 1)
self.assertEqual(m1.medal_type, "gold")
self.assertEqual(m1.event, "Women's Badmiton")
def test_2(self):
m2 = OlympicMedal("Men's Marathon", 7)
self.assertEqual(m2.medal_type, 0)
self.assertEqual(str(m2), "Men's Marathon :: unknown")
self.assertEqual(repr(m2), "Men's Marathon :: unknown")
if __name__ == '__main__':
unittest.main()
PRBE Errors in Python Class and Test Filles. Correct the errors in source code in the...
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...
9c
Python
1) What is the output of the following code? Refer to the Weapon, Blaster, and Bowcaster classes. File 1: weapon.py class Weapon: def init ( self, power ): self.mPower = power return Example: import blaster from bowcaster import Bowcaster def getPower( self ): return self.mPower han = blaster.Blaster( 8000, 20 ) print("HP:", han.getPower( ) ) print( "HR:", han.getFireRate()) chewie = Bowcaster( 3000, 6) print( "CB:", chewie.getBarrelSize()) print( "CR:", chewie.getRange()) File 2: blaster.py import weapon class Blaster( weapon. Weapon):...
11p
Python Language
Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...
11q
Language is python need help
1) What is the output of the following code? Refer to the class defined here. Example: File 1: asset.py import asset class Asset: brains = asset.Asset( "Brains" ) strength = asset. Asset( "Strength" ) steel = asset.Asset( "Steel" ) wheelbarrow = asset. Asset( "Wheelbarrow" ) cloak = asset.Asset( "Cloak" ) def _init__( self, name): self.mName = name return def getName( self ): return self.mName al = strength + steel a2 = cloak + wheelbarrow...
Python 3+ Adjust the following code so the two errors below are non-present: 1. __init__() : Since Pizza object don't have it's own set() datastructure, the toppings in the pizza object are manimupated from out of the object. (-1.0) 2. __eq__() : How about "self.toppings == other.toppings" rather than "self.toppings - other.toppin == set())". Code: ## Program 1 ## --------------------------------- class Pizza: def __init__(self, s='M', top=set()): self.setSize(s) self.toppings = top def setSize(self, s): self.size = s def getSize(self): return self.size...
Python only please, thanks in advance.
Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
I have to write a program where the program prints a deck of
cards. instead of having your regular suits and numbers the program
will use a value for a number, id will be either rock, paper, or
scissors, and the coin will be heads or tails. print example: 2 of
rock heads. If the user is enters 1 the program will print out 30
of the print example and arrange them by there values. if the user
enters 2...
import math ''' Finish the code below as described. Use the completed class Square as an example. ''' class Square: ''' Each Square has a width and can calculate its area, its perimeter, and return a string representation of itself. ''' def __init__(self, width): ''' (float) -> None Create a new Square with the given width. ''' self.width = width def get_area(self): ''' () -> float Return this square's area. ''' return self.width*self.width def get_perimeter(self): ''' () -> float Return...
Please code in Python Revise the AbstractBag class so that it behaves as a subclass of AbstractCollection provided in the file abstractcollection.py. Abstractcollection.py code: class AbstractCollection(object): """An abstract collection implementation.""" # Constructor def __init__(self, sourceCollection = None): """Sets the initial state of self, which includes the contents of sourceCollection, if it's present.""" self.size = 0 if sourceCollection: for item in sourceCollection: self.add(item) # Accessor methods def isEmpty(self): """Returns True if len(self) == 0, or False otherwise.""" return len(self) == 0...
Python only please, thanks in advance.
Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...