I have written a program for problem code ZCO14001 and submitted it but it didn’t even pass one test case. The thing is the I think the program is correct and I was also able to get the correct output for the two sample cases when I enter them myself so even if it was not fully correct, I should have some test cases pass atleast.
class Controls:
def __init__(self, end, max_h, stack):
self.position = 0
self.end = end
self.stack = stack
self.max = max_h
self.is_loaded = False
def move_left(self):
if self.position > 0:
self.position -= 1
def move_right(self):
if self.position < self.end-1:
self.position += 1
def pick(self):
if self.stack[self.position] > 0 and not self.is_loaded:
self.stack[self.position] -= 1
self.is_loaded = True
def drop(self):
if self.stack[self.position] < self.max and self.is_loaded:
self.stack[self.position] += 1
self.is_loaded = False
line1 = input()
line1 = line1.split(" ")
stack_no = int(line1[0])
max_height = int(line1[1])
line2 = input()
line2 = list(map(int, line2.split(" ")))
while len(line2) < stack_no:
line2.append(0)
line3 = input()
line3 = list(map(int, line3.split(" ")))
controller = Controls(stack_no, max_height, line2)
for instruction in line3:
if instruction == 0:
break
elif instruction == 1:
controller.move_left()
elif instruction == 2:
controller.move_right()
elif instruction == 3:
controller.pick()
elif instruction == 4:
controller.drop()
else:
print("Error")
print(controller.stack)
I am using python 3.6. Can anyone tell me if my program is incoreect or if it just isn’t formatted correctly? I am a noob so thanks for help.