Question: we are using python combination lock for a gym locker, as shown to the right. The lock is constructed with a combination - three numbers


combination lock for a gym locker, as shown to the right. The lock is constructed with a combination - three numbers between 0 and 59 (inclusive). The reset method resets both (a) the dial so that it points to 0 and (b) the internal state. The turn_clockwise and turn_counterclockwise methods tum the dial by a given number of ticks clockwise or counterclockwise, respectively. The get state method returns a tuple representing the internal state. The is open method attempts to open the lock. The lock opens if the user tumed it clockwise to the first number in the combination, then counterclockwise to the second, and then clockwise to the third. Here is a list of methods that you need to implement in the ComboLock class: 1) [20 marks] A constructor that takes three integers, each between 0 and 59 (inclusive), that represent the lock's "secret" combination. Validation of the three integers is required, and invalid arguments must rai se an appropriate exception: TypeError and ValueError. For example: 2) [10 marks] The method repr returns a string representation of a Combolock object. For example: k=ComboLock(10,20,30)kmbolock(10,20,30)nt(lock)mboLock(10,20,30) 3) [25 marks] The method turn clockwise takes an integer representing the number of ticks and turns the dial clockwise by the given number of ticks. Two clockwise turns of 5 and 10 ticks are equivalent to a single turn of 15 ticks. For simplicity, complete turns of the dial do not interfere with entering the combination, e.g., a clockwise turn of 75 ticks is equivalent to a clockwise turn of 15 ticks. NOTE: The method get state is described in the next question, and it will be used to test most of your functions. For example: \( \begin{aligned} \gg & \text { lock }=\text { ComboLock(10, 20, 30) } \\ \gg & \text { lock.get_state(0) } \\ & \text { (0, None, None, None) } \\ & \text { lock.turn_clockwise(5) } \\ & \text { lock.get_state0 } \\ & \text { (5,5, None, None) } \\ & \text { lock.turn_clockwise(7) } \\ & \text { lock.get_state0 } \\ & (12,12, \text { None, None) } \\ & \end{aligned} \) 4) [5marks] The methodget_ state returnsa4-tuplerepresenting the internalstate of the lock. The first element represents the dial position. The second element represents the state of the initial clockwise turn(s). The third element represents the state of the counterclockwise turn(s) that followed those initial clockwise turns. The fourth element represents the state of the final clockwise turn(s). IMPORTANT: Although the implementation of get_state is worth only 5 marks, it is r equired. Failure to correctly implement get state will cause most other tests to fail. For example: 5) [5 marks] The method reset resets both (a) the dial so that it points to 0 and the intemal state. For example: lock = ComboLock (10,20,30) lock.turn_clockwise(5) lock.get_state0 (5, 5, None, None) > lock.reset? lock.get_state0 (0, None, None, None) 6) [25 marks] The method turn counterclockwise takes an integer representing the number of ticks and turns the dial counterclockwise by the given number of ticks. Counterclockwise turns that immediately follow a reset impact the dial, but they do not impact the last 3 elements of the tuple. For example: s>> lock = ComboLock (10,20,30) > lock.get_state0 (0, None, None, None) lock.turn_clockwise(13) >> lock.get_state(0 (13,13, None, None) lock.turn_counterelockwise(5) lock.get_state0 (8,13,8, None) lock.turn_clockwise(10) lock.get_state) (18,13,8,18) 7) [10 marks] The method is open returns True if the lock opens and False otherwise. For example: lock =ComboLock(10,20,30) lock.turn_clockwise(10) lock.is_open0 False lock.turn_counterclockwise(50) lock.is_open0) False lock.turn_clockwise(70) lock.is_open0 True Acknowledgement: the assignment specification is adapted from "Java for Everyone" by C. S.Horstmann
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
