Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
393be86
Add hello world program
kevinrockwell Sep 12, 2019
a322a75
Add Chapter 1 Assignment
kevinrockwell Sep 15, 2019
b74cab8
Change teams dict to store comp locations in list
kevinrockwell Sep 15, 2019
98a050e
Add input from terminal
kevinrockwell Sep 18, 2019
5c37ac8
Add output
kevinrockwell Sep 18, 2019
713195a
Make teams dictionary use integer keys
kevinrockwell Sep 26, 2019
5a407a8
Revert "Change teams dict to store comp locations in list"
kevinrockwell Sep 27, 2019
ab5af87
Make output work for competiton locations
kevinrockwell Sep 27, 2019
f6189ae
Add Ch 2 assignment
kevinrockwell Oct 2, 2019
9c0d553
Prevent already added teams from being readded
kevinrockwell Oct 3, 2019
fd12e45
Make modify prompt for attributes
kevinrockwell Oct 4, 2019
dfc0eeb
Add basic input functions and general program structure
kevinrockwell Oct 16, 2019
c48e123
Fix input functions, rename get_int to get_positive_int
kevinrockwell Oct 16, 2019
93b1159
Add get_bool function
kevinrockwell Oct 16, 2019
4ce1691
Add attributes list, tweak wording in get_bool
kevinrockwell Oct 16, 2019
8385a99
Add get_comps and finish add team
kevinrockwell Oct 16, 2019
40f2362
Implement team deletion
kevinrockwell Oct 16, 2019
54667db
Implement list teams (stolen from Ch 2)
kevinrockwell Oct 16, 2019
cdc5285
Implement basic search
kevinrockwell Oct 16, 2019
4399c79
Implement exit
kevinrockwell Oct 16, 2019
326eee9
Implement modify, fix some stuff
kevinrockwell Oct 17, 2019
88ecee7
Add Ch 4 Assignment
kevinrockwell Oct 21, 2019
8238612
Add more comments to Ch 4 assignment
kevinrockwell Oct 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ch_1_Kevin_Rockwell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, world!")
112 changes: 112 additions & 0 deletions ch_1_assign_kevin_rockwell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
teams = { #Stores all the teams with string form of team number as key
1: {
"location": "Pontiac, Michigan, USA",
"rookie_year": 1997,
"competed_2019": True,
"2019_comps": {
"FIM District Center Line Event 2019": "Center Line, MI, USA",
"FIM District Troy Event 2019": "Troy, MI, USA",
},
},
16: {
"location": "Mountain Home, Arkansas, USA",
"rookie_year": 1996,
"competed_2019": True,
"2019_comps": {
"Midwest Regional": "Chicago, IL, USA",
"Rocket City Regional 2019": "Huntsville, AL, USA",
"Darwin Division 2019": "Detriot, MI, USA",
},
"2019_awards": [
"Industrial Design Award sponsored by General Motors",
"Regional Finalists",
"Excellence in Engineering Award sponsored by Delphi",
],
},
253: {
"location": "Millbrae, California, USA",
"rookie_year": 1999,
"competed_2019": True,
"2019_comps": {
"San Fransisco Regional": "San Fransisco, CA, USA",
"Monterey Bay Regional": "Seaside, CA, USA",
"Newton Divison": "Houston, TX, USA"
},
"2019_awards": [
"Team Spirit Award sponsored by FCA Foundation",
],
},
342: {
"location": "North Charleston, South Carolina, USA",
"rookie_year": 2000,
"competed_2019": True,
"2019_comps": {
"Palmetto Regional 2019": "Myrtle Beach, SC, USA",
"Rocket City Regional 2019": "Huntsville, AL, USA",
},
"2019_awards": [],
},
554: {
"location": "Ft. Thomas, Kentucky, USA",
"rookie_year": 2001,
"competed_2019": True,
"2019_comps": {
"Miami Valley Regional 2019": "Fairborn, OH, USA",
},
"2019_awards": [],
}
}

#Attributes that can be input as keys, their discription as values
valid_requests = {
"location": "Team's location",
"rookie_year": "Team's rookie year",
"competed_2019": "Seeing if team competed in 2019",
"2019_comps": "A list of the competitions the team competed in for 2019",
"comp_locations": "The location of the 2019 competitions",
"2019_awards": "Awards won during the 2019 season",
}


print("Valid teams:")
print(" ".join(map(str, teams.keys()))) #Print teams seperated by spaces onto one line
requested_team_number = ""

while requested_team_number == "": #loop until valid input
requested_team_number = input("Team Number: ")
if requested_team_number.isdigit(): #Tests if input is only digits
if int(requested_team_number) in teams:
team_number = int(requested_team_number)
else:
print(f"Team number '{requested_team_number}' not stored.")
requested_team_number = ""

else:
print(f"Invalid team number '{requested_team_number}'")
requested_team_number = ""


print("Valid Requests:")
for attribute in valid_requests: #loop through keys in valid_attributes
print(f"'{attribute}' for {valid_requests[attribute]}") #prints name/function
requested_attribute = ""
while requested_attribute == "": #loop until valid input
#Case insensitive input, spaces replaced w/underscore
requested_attribute = input("Attribute: ").lower().replace(" ", "_")

if requested_attribute not in valid_requests:
print(f"Attribute {requested_attribute} not recognized.")
requested_attribute = ""
if requested_attribute != "comp_locations":
requested_attribute_value = teams[team_number][requested_attribute]
else:
requested_attribute_value = teams[team_number]["2019_comps"]
print(f"Team {requested_team_number}'s {requested_attribute}:")
if isinstance(requested_attribute_value, list):
for value in requested_attribute_value:
print(value)
elif isinstance(requested_attribute_value, dict):
for event in requested_attribute_value:
print(f"{event} - {requested_attribute_value[event]}")
else:
print(requested_attribute_value)
183 changes: 183 additions & 0 deletions ch_2_assign_kevin_rockwell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
teams = {}

def get_team_num():
print("Enter team number or 'c' to cancel")
while True:
team_num = input("Team Number: ").lower().rstrip()
if team_num.isdigit():
return int(team_num)
elif team_num.lower() == "c":
return ""
else:
print(f"Invalid Team Number {team_num}")

def get_vision():
while True: #Limit Vision to True or False
vision = input("Team Has Vision System [True/False]: ").lower().rstrip()
if vision == "t" or vision == "true":
return True
elif vision == "f" or vision == "false":
return False
elif vision == "":
return "Unknown"
else:
print(f"Invalid Value {vision}, expected True or False")

def get_drivetrain_motors():
while True: #Limit Number of motors to int
motors = input("Number of Drivetrain Motors (Integer): ")
if motors.isdigit():
return int(motors)
elif motors == "":
return "Unknown"
else:
print(f"Invalid Motor Number {motors}")

def get_input(prompt):
"""Takes input, returns None for Blank String"""
response = input(prompt)
if response != "":
return response
else:
return "Unknown"

def print_team(team_num, team):
print(f"Team {team_num} - {team['name']}\n") #Print Number - Name
print(f"Programming Language: {team['lang']}")
print(f"Robot Length: {team['length']}")
print(f"Robot Width: {team['width']}")
print(f"Has Vision System: {team['vision']}")
print(f"Number of Drivetrain Motors: {team['motors']}")

def get_team_data():
temp_team = {} #Store unentered values as blank string
print("Input team data, enter blank line to skip data point")
#Store Unknowns as "Unknown" using get_input
temp_team["name"] = get_input("Team name:\n")
temp_team["lang"] = get_input("Programming Language: ")

#Keep dimensions as str to allow arbitrary dimensions
temp_team["width"] = get_input("Robot Width: ")
temp_team["length"] = get_input("Robot Length: ")

temp_team["vision"] = get_vision()
temp_team["motors"] = get_drivetrain_motors()
return temp_team

while True:
#Print main menu
print("""
Allowed Actions:
(a)dd Team
(v)iew team data
(m)odify team data
(r)emove team
(s)earch for teams
(l)ist all teams
(e)xit
""")
selection = ""
selection = input("Action: ")
if selection == "a": #Add team
team_num = get_team_num()
if team_num == "": #User canceled add operation
continue #Go back into main menu loop
elif team_num in teams.keys():
print(f"Team Number {team_num} already in ")
temp_team = get_team_data()

while True: #Confirm before saving
save = input(f"Save team {team_num}? [Y/n]").lower()
if save == "y" or save == "":
teams[team_num] = temp_team
break
elif save == "n":
break

elif selection == "v": #View team
team_num = get_team_num()
print_team(team_num, teams[team_num])

elif selection == "m": #modify team
team_num = get_team_num()
if team_num not in teams.keys():
print(f"Team Number {team_num} not stored.")
continue
print(f"Modifying team {team_num}")
while True: #Confirm before saving
print("""
Select Attribute to Modify, or 'e' to return to main menu:
(n)ame
(p)rogramming language
(w)idth
(l)ength
(v)ision
(m)otor numbers in drietrain
""")
to_modify = input("Selection: ")
if to_modify == "n":
teams[team_num]["name"] = get_input("Enter Name: ")
elif to_modify == "p":
teams[team_num]["lang"] = get_input("Enter Language: ")
elif to_modify == "w":
teams[team_num]["width"] = get_input("Enter Width: ")
elif to_modify == "l":
teams[team_num]["length"] = get_input("Enter Length: ")
elif to_modify == "v":
teams[team_num]["vision"] = get_vision()
elif to_modify == "m":
teams[team_num]["motors"] = get_drivetrain_motors()
elif to_modify == "e":
break
else:
print("Invalid Action")

elif selection == "r": #remove team
team_num = get_team_num()
if team_num != "":
if team_num in teams.keys():
del teams[int(team_num)]
else:
print(f"Invalid Team Number {team_num}")
else:
continue #user canceled, so return to main menu

elif selection == "s": #search for teams
search_str = input("Search for team by name or number: ")
matches = []
if search_str.isdigit():
for team, dat in teams.items():
if str(team).startswith(search_str): #if start if numbers match
matches.append(f"{team}: {dat['name']}") #number + name
else:
for team, dat in teams.items():
if dat["name"].startswith(search_str): #if start of name match
matches.append(f"{team}: {dat['name']}") #num + name

if matches != []:
print(f"Matches to {search_str}")
for m in matches:
print(m)
else:
print(f"No matches for {search_str}")

elif selection == "l": #list teams
if len(teams.keys()) < 1:
print("No stored teams")
continue
print("Stored Teams:")
temp_ls = [] #used to store numbers temporarily to print nicer
for team in teams.keys():
if len(temp_ls) < 4: #print 4 numbers per line
temp_ls.append(str(team))
else:
print(" ".join(temp_ls))
temp_ls = [str(team)]
else:
print(" ".join(temp_ls))

elif selection == "e": #exit program
break

else:
print(f"Invalid Action: {selection}\n")
Loading