Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications; The constructor should not

***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications;

  • The constructor should not take any arguments; a coin always has two sides
  • add a flip() method that uses the roll() method from the parent class. If roll returns 1; flip should return "HEADS". If roll returns a 2, flip should return "TAILS"
  • Do not override the roll or rollMultiple methods from the parent class

#!/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")

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: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago