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

Hi this is a homework i got from school in PYTHION and so far i only found Java

ID: 3693579 • Letter: H

Question

Hi this is a homework i got from school in PYTHION and so far i only found Java examples. Can you help me ? Thank youImplement a class ComboLock that works like the combination lock in a gym locker, as shown here. The lock is constructed with a combination—three numbers between 0 and 39. The reset method resets the dial so that it points to 0. The turnLeft and turnRight methods turn the dial by a given number of ticks to the left or right. The open method attempts to open the lock. The lock opens if the user first turned it right to the first number in the combination, then left to the second, and then right to the third. class ComboLock : def ComboLock(self, secret1, secret2, secret3) def reset(self) : . . . def turnLeft(self, ticks) : . . . def turnRight(self, ticks) : . . . def open(self) : . . .

Explanation / Answer

# python class class ComboLock that works like the combination lock
#in a gym locker The lock is constructed with a
#combina­tion—three numbers between 0 and 39. The reset method
#resets the dial so that it points to 0. The turnLeft and turnRight
#methods turn the dial by a given number of ticks to the left or
#right. The open method attempts to open the lock. The lock opens
#if the user first turned it right to the first number in the combina-
#tion, then left to the second, and then right to the third.

class Lock:

#constructor
def __init__(self, secret1, secret2, secret3, dial):
self.secret1 = secret1
self.secret2 = secret2
self.secret3 = secret3
self.dial = dial

# reset function
def reset(self):
self.dial = 0


# turnLeft function
def turnLeft(self, ticks):
self.scroll(self,-ticks)
if self.secret1 == -1:
if secret1.shouldUnlock(self,secret2):
print "Secret 2 unlocked"

#turnRight function
def turnRight(self, ticks):
self.scroll(self, ticks)
if secret1.shouldUnlock(self, secret2):
print "Secret 1 unlocked"
if self.shouldUnlock(self, secret2):
if self.shouldUnlock(self, secret3):
print "Combo lock unlocked"


# scroll function
def scroll(self,ticks):
if self.dial + ticks > 39:
if ticks >= 39:
self.dial = self.dial + ticks - 39

elif self.dial + ticks < 0:
self.dial = self.dial + 40 + ticks
self.dial = self.dial + ticks - 40
else:
self.dial = self.dial + ticks

#shouldUnlock function
def shouldUnlock(self,secret):
if self.dial == secret:
secret = -1
return True
else:
return False

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote