Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write two classes for weapons in a fantasy role-playing game. The first class, W

ID: 3654247 • Letter: W

Question

Write two classes for weapons in a fantasy role-playing game. The first class, Weapon, a generic class upon which all other weapon classes will be based, should define just one attribute: -> damage - represents the amount of damage the weapon inflicts when used. It should have a default value of 0. The class should define one method: -> _init_()- accepts a value into a parameter and assigns it to the objects new attribute damage. The second class, Sword, should be derived from Weapon and define a single method: -> swing() - displays the message "You swing and infict XX damage points, where XX is equal to the objects attribute damage. Also: Instantiate a Sword that causes 5 points of damage, and swing it twice.

Explanation / Answer

# this code is working.... check it out


class Weapon():

def __init__(self,dam):

self.damage = dam

class Sword(Weapon):

def swing(self):

print "You swing and infict "+str(self.damage)+" damage points"


testSword = Sword(5)

testSword.swing()

testSword.swing()