-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot_creator.py
More file actions
146 lines (126 loc) · 3.57 KB
/
robot_creator.py
File metadata and controls
146 lines (126 loc) · 3.57 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# /usr/bin/python
#-*- coding: utf-8 -*-
# Imports
import sys
# Variables
usr = ''
helplist = '''-------------------- Commands --------------------
!create - Creates a new robot
!list - Displays a list of created robots
!show - Shows information about a specific robot
!delete - Deletes an existing robot
!about - Displays information about the program
!exit - Exits the program'''
robots = []
rid = 1
aboutmsg = '''
===============================
File name: robot_creator
Version: 3.1
Author: Blackman White
Date created: 9/30/2018
Date last modified: 10/1/2018
Python Version: 3.7
================================='''
# Functions
class Robot:
def __init__(self, name, color):
global rid
self.name = name
self.color = color
self.id = rid
rid += 1
def info(self):
print("\n----- {}'s information -----".format(self.name))
print("Name:", self.name)
print("Color:", self.color)
print("ID:", self.id)
print("------------------------------")
def __del__(self):
print("{} has been deleted".format(self.name))
def menu():
global usr
usr_i()
if usr == "!help":
print(helplist)
menu()
elif usr == "!create":
create_r()
menu()
elif usr == "!list":
list_r()
menu()
elif usr == "!show":
show_r()
menu()
elif usr == "!delete":
delete_r()
menu()
elif usr == "!about":
print(aboutmsg)
menu()
elif usr == "!exit":
sys.exit(0)
else:
print("Invalid command")
print("Type !help to see commands\n")
menu()
def usr_i():
global usr
usr = input('\n> ')
def create_r():
global robots
print("\n===== Robot Creator =====")
a = input("Name: ")
a = a.title()
for robot in robots:
if a.lower() == robot.name.lower():
print("\nA robot with that name already exists, delete the existing robot or pick another name\n")
return None
else:
pass
b = input("Color: ")
r = Robot(a,b)
robots.append(r)
def list_r():
global robots
if not robots:
print("There are no robots existent, type !create to create a robot")
return None
print("------ Robots ------\n")
for robot in robots:
print("[{}] {}".format(robot.id,robot.name))
print("\n--------------------")
def show_r():
global robots
if not robots:
print("There are no robots existent, type !create to create a robot")
return None
usr = input("Enter robot name: ")
robot_found = False
for robot in robots:
if usr.lower() == robot.name.lower():
robot_found = True
robot.info()
return None
if robot_found == False:
print("Robot not found")
def delete_r():
global robots
if not robots:
print("There are no robots existent, type !create to create a robot")
return None
usr = input("Enter robot name: ")
robot_found = False
for robot in robots:
if usr.lower() == robot.name.lower():
robot_found = True
robots.remove(robot)
del robot
return None
if robot_found == False:
print("Robot not found")
# Main
print("========== Menu ==========")
print("Type !help to see commands")
menu()