-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot_app.py
45 lines (39 loc) · 1.32 KB
/
robot_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
from toy_robot import *
# Clear screen
os.system('cls' if os.name == 'nt' else 'clear')
# CLI menu
main_menu = ["PLACE", "MOVE", "LEFT", "RIGHT", "REPORT"]
# Class global vars.
if __name__ == "__main__":
def define_place():
global x, y, direction
input_x, input_y, input_direction = input("Enter 'x', 'y' & 'direction' (x,y,direction): ").split(',')
x = int(input_x)
y = int(input_y)
direction = input_direction.upper()
return
try:
define_place()
play = ToyRobot()
play.place(x, y, direction)
while x in range(5) and y in range(5) and direction in dir_list:
choice = input("Choose command (PLACE/MOVE/LEFT/RIGHT/REPORT): ")
if choice.upper() == main_menu[0]:
define_place()
play.place(x, y, direction)
elif choice.upper() == main_menu[1]:
play.move()
elif choice.upper() == main_menu[2]:
play.left()
elif choice.upper() == main_menu[3]:
play.right()
elif choice.upper() == main_menu[4]:
print(play.report())
else:
break
continue
except InputError:
print("Invalid input")
except ValueError:
print("Invalid input")