40 lines
865 B
Python
40 lines
865 B
Python
class Dial:
|
|
value = 50
|
|
reached_zero = 0
|
|
|
|
def CrankLeft(self, clicks):
|
|
self.value -= clicks
|
|
if self.value < 0:
|
|
self.value = abs(self.value % int(100))
|
|
if self.value == 0:
|
|
self.reached_zero += 1
|
|
|
|
def CrankRight(self, clicks):
|
|
self.value += clicks
|
|
if self.value > 99:
|
|
self.value = abs(self.value % int(100))
|
|
if self.value == 0:
|
|
self.reached_zero += 1
|
|
|
|
def PrintValue(self):
|
|
print(self.value)
|
|
|
|
def printSolution(self):
|
|
print( f'The dial reached zero {self.reached_zero} times')
|
|
|
|
|
|
MyDial = Dial()
|
|
file = input("enter input file:")
|
|
with open(file) as f:
|
|
for line in f:
|
|
ticks = int(line[1:-1])
|
|
if line[0] == 'L':
|
|
print("Crank Left")
|
|
MyDial.CrankLeft(ticks)
|
|
elif line[0] == 'R':
|
|
print("Crank Right")
|
|
MyDial.CrankRight(ticks)
|
|
MyDial.PrintValue()
|
|
MyDial.printSolution()
|
|
|