4. (30 points) Create a class to model a power drill, like the one in the pictur
ID: 3731735 • Letter: 4
Question
4. (30 points) Create a class to model a power drill, like the one in the picture (https://openelipart.org/detail/216781/electric-screwdriver). The drill has a rechargeable battery with a power level between 0 and 100. The drill also takes drill bits, numbered from 1 to 20. Your class will powid th following methods: init_(self): This is the constructor of the class. At creation, the power drilled is fully charge, does not have a drill bit attached. (5 points) sOutOf Power(self): returns True if the battery has been completely drained. Otherwise, it returns False isBitAttached(self): returns True if the power drill has a drill bit attached to it. (2.5 points) . (2.5 points) setBit(self, bit_number): installs a bit, of number bit_number, in the power drill. (5 points) drill self, seconds): This method simulates turning the drill on for time indicated by the parameter seconds (which should be a positive number). Drilling can occur only if the battery level is at least (seconds 2) and the power drill has a drill bit attached to it.If we can drill, this method reduces the power level of the battery by (seconds 2) units recharge(self, seconds): this method increases the power level of the battery by (seconds 2) units. The battery should not overcharge because it could explode. (10 points) (5 points)Explanation / Answer
class PowerDrill:
def __init__(self):
self.battery = 0
self.drillbit = 0
def setBit(self, bit_number):
if bit_number < 0 or bit_number > 20:
print("Invalid bit number.valid range 1-20")
else:
self.drillbit = bit_number
def isOutOfPower(self):
if self.battery == 0:
return True
else:
return False
def isBitAttached(self):
if self.drillbit == 0:
return True
else:
return False
def drill(self, seconds):
if self.battery < seconds * 2:
print("It can not run due to low power")
else:
self.battery = self.battery - seconds * 2;
if self.battery < 0:
self.battery = 0
def recharge(self, seconds):
self.battery = self.battery + 2 * seconds
if self.battery > 100:
self.battery = 100
c = PowerDrill()
c.recharge(50)
c.setBit(10)
c.drill(10)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.