class Car:
def __init__(self, pos=0):
self.pos = pos
def move(self, direction):
self.pos = self.pos + direction
def get_position(self):
return self.pos
def main():
n = int(input())
car = Car()
for _ in range(n):
instruction = input()
if instruction == "MOVE":
distance = int(input())
car.move(distance)
elif instruction == "POSITION":
position = car.get_position()
print(position)
if __name__ == '__main__':
main()
I really dont know why its not working
I tried to launch it and for some reason when you type MOVE 100 or any number it still stays in same position
>Solution :
Because "MOVE 100" is considered as one input, so with instruction = input() and this MOVE 100 as input, instruction will be "MOVE 100", not "MOVE", in order to separate them, you can either do the following:
instruction = input()
if instruction.startswith("MOVE"):
distance = int(instruction.split(' ')[1])
car.move(distance)
Or you can keep your code the same, but you can change the input so that you input MOVE and 100 separately.