***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications;
#!/usr/bin/python
# your class definition goes here
from random import randint
class Die(object):
def __init__(self, sides):
self.sides = sides
def roll(self):
return randint(1, self.sides)
def rollMultiple(self, number):
lst = []
for i in range(number):
lst.append(self.roll())
return lst
def getSides(self):
return self.sides
# testing code
# please do not edit
myd = Die(6)
md = myd.rollMultiple(1000)
if type(myd.roll()) is int:
print("test 1 pass")
if len(md) == 1000:
print("test 2 pass")
if max(md) == 6:
print("test 3 pass")
if min(md) == 1:
print("test 4 pass")
if myd.getSides() == 6:
print("test 5 pass")
You should use the following format for the new code:
#!/usr/bin/python
# Die and Coin classes go here
# testing code
# please do not edit
myCoin = Coin()
if myCoin.roll() > 0 and myCoin.roll() < 3:
print("test 1 pass")
resFlip = myCoin.flip()
if resFlip == 'HEADS' or resFlip == "TAILS":
print("test 2 pass")#!/usr/bin/python
# Die and Coin classes go here
from random import randint
class Die(object):
def __init__(self, sides):
self.sides = sides
def roll(self):
return randint(1, self.sides)
def rollMultiple(self, number):
lst = []
for i in range(number):
lst.append(self.roll())
return lst
def getSides(self):
return self.sides
class Coin(Die):
def __init__(self):
super(Coin, self).__init__(2)
def flip(self):
if self.roll() == 1:
return "HEADS"
else:
return "TAILS"
# testing code
# please do not edit
myCoin = Coin()
if myCoin.roll() > 0 and myCoin.roll() < 3:
print("test 1 pass")
resFlip = myCoin.flip()
if resFlip == 'HEADS' or resFlip == "TAILS":
print("test 2 pass")
***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from...
12. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field .A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up The Coin class should have the following methods .A no-arg constructor that randomly determines the side of the coin that is facing up (heads" or "tails") and initializes the aideUp field accordingly .A void method named toss that simulates the...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
# JAVA Problem Toss Simulator Create a coin toss simulation program. The simulation program should toss coin randomly and track the count of heads or tails. You need to write a program that can perform following operations: a. Toss a coin randomly. b. Track the count of heads or tails. c. Display the results. Design and Test Let's decide what classes, methods and variables will be required in this task and their significance: Write a class called Coin. The Coin...
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...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name='' #declaring attributes in class address='' status='' sales_tax_percentage=0.0 def __init__(self,name,address,status,sales_tax_percentage): #init method to initialize the class attributes self.name=name self.address=address self.status=status self.sales_tax_percentage=sales_tax_percentage def get_name(self): #Getter and setter methods for variables return self.name def set_name(self,name): self.name=name def get_address(self): return self.address def set_address(self,address): self.address=address def set_status(self,status): self.status=status def get_status(self): return self.status def set_sales_tax_percentage(self,sales_tax_percentage): self.sales_tax_percentage=sales_tax_percentage def get_sales_tax_percentage(self): return self.sales_tax_percentage def is_store_open(self): #check store status or availability if self.status=="open": #Return...
PRBE Errors in Python Class and Test Filles. Correct the errors in source code in the O1ympicMeda traditional and unit rt c. Correct class and in the modules olympicmedal. code- do not recopy (5 Py, testi.py, and teat2.py. Mark your corrections directly on the source point penalty for recopying). Adding, deleting, or correcting a pair of parentheses braces ( { }), single quotes (·. double quotes (- .), or triple quotesぃ.. test scripts on pages 6 and 7. There are...
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...
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...
Copy the following Python fuction discussed in class into your file: from random import * def makeRandomList(size, bound): a = [] for i in range(size): a.append(randint(0, bound)) return a a. Rename the function sumList as meanList and modify it so that it finds the average of the list. The average is the sum divided by the size (len) of the list. Make sure that the function doesn't give you an error when it is called on an empty list. The...