Эй, я пробую этот дополнительный кредитный файл здесь, который я здесь приложил.Я получаю ошибку трассировки, что я не понимаю, почему это происходит
https://drive.google.com/file/d/0B_K2RFTege5uRF9IeGJiYllQbGs/view?usp=sharing
Я использую Python 3.4.3
Please enter a direction from the list above.: up
Please enter how many steps you would like to take.: 5
Traceback (most recent call last):
File "D:\Downloads\programming-assignment-5.py", line 63, in <module>
main()
File "D:\Downloads\programming-assignment-5.py", line 61, in main
move_robot(direction,steps)
File "D:\Downloads\programming-assignment-5.py", line 28, in move_robot
start[1].append(int(step))
AttributeError: 'int' object has no attribute 'append'
Вот код, который я до сих пор:
import math
import sys
def calculate_distance(pos1, pos2):
pos1 = [x,y]
pos2 = [x,y]
#distance = math.sqrt((((-)**2)+((-)**2))
def command_list():
print("Utilize the folowing commands")
print("Up, Down, Left, Right")
print("press 'E' to Exit")
def move_robot(step_sequence,step):
x = 0
y = 0
start = [0,0]
#end = [x,y]
#print(start)
moveRobot = [["up"],["down"],["left"],["right"]]
while step_sequence != "e":
if moveRobot[0][0] == step_sequence:
#x = x + int(step)
#start.append(int(step))
start[1].pop(0)
start.insert[1](step)
print("you moved UP",step, "space")
print(start)
elif moveRobot[1][0] == step_sequence:
print("You moved DOWN 1 space")
down = 0
elif moveRobot[2][0] == step_sequence:
print("You moved LEFT 1 space")
left = 0
elif moveRobot[3][0] == step_sequence:
print("You moved RIGHT 1 space")
right = 0
elif step_sequence == "e":
sys.exit()
elif step_sequence != (moveRobot[0][0] or moveRobot[1][0] or moveRobot[2][0] or moveRobot[3][0]):
print()
print("You have Entered an Invalid command.")
print("Please enter one of the following commands.")
print("Up, Down, Left, Right")
print()
step_sequence = str(input("Please enter a direction from the list above.: "))
steps = int(input("Please enter how many steps you would like to take.: "))
print(start)
return
def main():
command_list()
print()
direction = str(input("Please enter a direction from the list above.: "))
steps = int(input("Please enter how many steps you would like to take.: "))
move_robot(direction,steps)
#calculate_distance(move_robot(direction,steps))
main()
и эта ошибка будет .....? – CoryKramer
Пожалуйста, разместите трассировку, она содержит много полезной информации. – Will
Нужно указать stacktrace, чтобы дать совет здесь. Также почему 'print (« вы переместили 1 космос »)' повторяется в каждом случае? – shuttle87