From 393be865a0ecf40fbe3530aa1cdb97dbabe0d6c9 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 11 Sep 2019 19:50:05 -0700 Subject: [PATCH 01/23] Add hello world program --- ch_1_Kevin_Rockwell.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 ch_1_Kevin_Rockwell.py diff --git a/ch_1_Kevin_Rockwell.py b/ch_1_Kevin_Rockwell.py new file mode 100644 index 0000000..1385fe3 --- /dev/null +++ b/ch_1_Kevin_Rockwell.py @@ -0,0 +1 @@ +print("Hello, world!") \ No newline at end of file From a322a7544c4885f925c563b62c79365d580aca15 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Sun, 15 Sep 2019 13:09:01 -0700 Subject: [PATCH 02/23] Add Chapter 1 Assignment - Create teams dictionary with data for 5 teams --- ch_1_assign_kevin_rockwell.py | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ch_1_assign_kevin_rockwell.py diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py new file mode 100644 index 0000000..2f774ec --- /dev/null +++ b/ch_1_assign_kevin_rockwell.py @@ -0,0 +1,65 @@ +teams = { #Stores all the teams with string form of team number as key + "1": { + "lcoation": "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", + }, + "2019_awards": [ + "Imagery Award in honor of Jack Kamen", + ], + }, + "16": { + "lcoation": "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": [], + } + +} + + + From b74cab82af7ea91d663993dcf2a0d92d254de287 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Sun, 15 Sep 2019 13:36:12 -0700 Subject: [PATCH 03/23] Change teams dict to store comp locations in list - Makes it easier to access --- ch_1_assign_kevin_rockwell.py | 74 ++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py index 2f774ec..2233af5 100644 --- a/ch_1_assign_kevin_rockwell.py +++ b/ch_1_assign_kevin_rockwell.py @@ -1,25 +1,34 @@ teams = { #Stores all the teams with string form of team number as key "1": { - "lcoation": "Pontiac, Michigan, USA", + "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", - }, + "2019_comps": [ + "FIM District Center Line Event 2019", + "FIM District Troy Event 2019", + ], + "comp_locations": [ + "Center Line, MI, USA", + "Troy, MI, USA", + ] "2019_awards": [ "Imagery Award in honor of Jack Kamen", ], }, "16": { - "lcoation": "Mountain Home, Arkansas, USA", + "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_comps": [ + "Midwest Regional", + "Rocket City Regional 2019", + "Darwin Division 2019", + ], + "comp_locations": [ + "Chicago, IL, USA", + "Huntsville, AL, USA", + "Detriot, MI, USA", + ] "2019_awards": [ "Industrial Design Award sponsored by General Motors", "Regional Finalists", @@ -30,11 +39,16 @@ "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_comps": [ + "San Fransisco Regional", + "Monterey Bay Regional", + "Newton Divison", + ], + "comp_locations": [ + "San Fransisco, CA, USA", + "Seaside, CA, USA", + "Houston, TX, USA", + ] "2019_awards": [ "Team Spirit Award sponsored by FCA Foundation", ], @@ -43,23 +57,37 @@ "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_comps": [ + "Palmetto Regional 2019", + "Rocket City Regional 2019", + ], + "comp_locations": [ + "Myrtle Beach, SC, USA", + "Huntsville, AL, USA", + ] "2019_awards": [], }, "554": { "location": "Ft. Thomas, Kentucky, USA", "rookie_year": 2001, "competed_2019": True, - "2019_comps": { + "2019_comps": [ "Miami Valley Regional 2019": "Fairborn, OH, USA", - }, + ], + "comp_locations": [ + "Fairborn, OH, USA", + ] "2019_awards": [], } } - +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", +} From 98a050edb871119f311a97e72e46af070aaf10d9 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 18 Sep 2019 15:35:11 -0700 Subject: [PATCH 04/23] Add input from terminal - Print valid teams and attributes - Take inputs (case insensitive) and check to see if they are valid - Replace spaces in attribute input with underscores --- ch_1_assign_kevin_rockwell.py | 41 +++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py index 2233af5..6562842 100644 --- a/ch_1_assign_kevin_rockwell.py +++ b/ch_1_assign_kevin_rockwell.py @@ -10,7 +10,7 @@ "comp_locations": [ "Center Line, MI, USA", "Troy, MI, USA", - ] + ], "2019_awards": [ "Imagery Award in honor of Jack Kamen", ], @@ -28,7 +28,7 @@ "Chicago, IL, USA", "Huntsville, AL, USA", "Detriot, MI, USA", - ] + ], "2019_awards": [ "Industrial Design Award sponsored by General Motors", "Regional Finalists", @@ -36,7 +36,7 @@ ], }, "253": { - "location": "Millbrae, California, USA",. + "location": "Millbrae, California, USA", "rookie_year": 1999, "competed_2019": True, "2019_comps": [ @@ -48,7 +48,7 @@ "San Fransisco, CA, USA", "Seaside, CA, USA", "Houston, TX, USA", - ] + ], "2019_awards": [ "Team Spirit Award sponsored by FCA Foundation", ], @@ -64,7 +64,7 @@ "comp_locations": [ "Myrtle Beach, SC, USA", "Huntsville, AL, USA", - ] + ], "2019_awards": [], }, "554": { @@ -72,17 +72,17 @@ "rookie_year": 2001, "competed_2019": True, "2019_comps": [ - "Miami Valley Regional 2019": "Fairborn, OH, USA", + "Miami Valley Regional 2019", ], "comp_locations": [ "Fairborn, OH, USA", - ] + ], "2019_awards": [], } - } -valid_requests = { +#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", @@ -91,3 +91,26 @@ "2019_awards": "Awards won during the 2019 season", } + +print("Valid teams:") +print(" ".join(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 not in teams: + print(f"Team number {requested_team_number} not stored.") + 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 = "" + From 5c37ac87e119ebaf56175e4d3641d201d12ca899 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 18 Sep 2019 16:15:39 -0700 Subject: [PATCH 05/23] Add output --- ch_1_assign_kevin_rockwell.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py index 6562842..2dbf3a9 100644 --- a/ch_1_assign_kevin_rockwell.py +++ b/ch_1_assign_kevin_rockwell.py @@ -99,12 +99,12 @@ while requested_team_number == "": #loop until valid input requested_team_number = input("Team Number: ") if requested_team_number not in teams: - print(f"Team number {requested_team_number} not stored.") + print(f"Team number '{requested_team_number}' not stored.") 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 + 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 @@ -114,3 +114,10 @@ print(f"Attribute {requested_attribute} not recognized.") requested_attribute = "" +requested_attribute_value = teams[requested_team_number][requested_attribute] +print(f"Team {requested_team_number}'s {requested_attribute}:") +if isinstance(requested_attribute_value, list): + for value in requested_attribute_value: + print(value) +else: + print(requested_attribute_value) \ No newline at end of file From 713195a331230a0ba6e12e5f4db47369b5a602f1 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 25 Sep 2019 19:38:46 -0700 Subject: [PATCH 06/23] Make teams dictionary use integer keys --- ch_1_assign_kevin_rockwell.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py index 2dbf3a9..049d264 100644 --- a/ch_1_assign_kevin_rockwell.py +++ b/ch_1_assign_kevin_rockwell.py @@ -1,5 +1,5 @@ teams = { #Stores all the teams with string form of team number as key - "1": { + 1: { "location": "Pontiac, Michigan, USA", "rookie_year": 1997, "competed_2019": True, @@ -15,7 +15,7 @@ "Imagery Award in honor of Jack Kamen", ], }, - "16": { + 16: { "location": "Mountain Home, Arkansas, USA", "rookie_year": 1996, "competed_2019": True, @@ -35,7 +35,7 @@ "Excellence in Engineering Award sponsored by Delphi", ], }, - "253": { + 253: { "location": "Millbrae, California, USA", "rookie_year": 1999, "competed_2019": True, @@ -53,7 +53,7 @@ "Team Spirit Award sponsored by FCA Foundation", ], }, - "342": { + 342: { "location": "North Charleston, South Carolina, USA", "rookie_year": 2000, "competed_2019": True, @@ -67,7 +67,7 @@ ], "2019_awards": [], }, - "554": { + 554: { "location": "Ft. Thomas, Kentucky, USA", "rookie_year": 2001, "competed_2019": True, @@ -93,15 +93,23 @@ print("Valid teams:") -print(" ".join(teams.keys())) #Print teams seperated by spaces onto one line +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 not in teams: - print(f"Team number '{requested_team_number}' not stored.") + 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 @@ -114,7 +122,7 @@ print(f"Attribute {requested_attribute} not recognized.") requested_attribute = "" -requested_attribute_value = teams[requested_team_number][requested_attribute] +requested_attribute_value = teams[team_number][requested_attribute] print(f"Team {requested_team_number}'s {requested_attribute}:") if isinstance(requested_attribute_value, list): for value in requested_attribute_value: From 5a407a802fcf7ec8a863b0419d0ce155c8fa8cbf Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Thu, 26 Sep 2019 19:43:15 -0700 Subject: [PATCH 07/23] Revert "Change teams dict to store comp locations in list" makes competition location a dict again This reverts commit b74cab82af7ea91d663993dcf2a0d92d254de287. --- ch_1_assign_kevin_rockwell.py | 67 +++++++++++------------------------ 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py index 049d264..fffe853 100644 --- a/ch_1_assign_kevin_rockwell.py +++ b/ch_1_assign_kevin_rockwell.py @@ -3,32 +3,19 @@ "location": "Pontiac, Michigan, USA", "rookie_year": 1997, "competed_2019": True, - "2019_comps": [ - "FIM District Center Line Event 2019", - "FIM District Troy Event 2019", - ], - "comp_locations": [ - "Center Line, MI, USA", - "Troy, MI, USA", - ], - "2019_awards": [ - "Imagery Award in honor of Jack Kamen", - ], - }, + "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", - "Rocket City Regional 2019", - "Darwin Division 2019", - ], - "comp_locations": [ - "Chicago, IL, USA", - "Huntsville, AL, USA", - "Detriot, MI, USA", - ], + "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", @@ -39,16 +26,11 @@ "location": "Millbrae, California, USA", "rookie_year": 1999, "competed_2019": True, - "2019_comps": [ - "San Fransisco Regional", - "Monterey Bay Regional", - "Newton Divison", - ], - "comp_locations": [ - "San Fransisco, CA, USA", - "Seaside, CA, USA", - "Houston, TX, USA", - ], + "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", ], @@ -57,26 +39,19 @@ "location": "North Charleston, South Carolina, USA", "rookie_year": 2000, "competed_2019": True, - "2019_comps": [ - "Palmetto Regional 2019", - "Rocket City Regional 2019", - ], - "comp_locations": [ - "Myrtle Beach, SC, USA", - "Huntsville, AL, USA", - ], + "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", - ], - "comp_locations": [ - "Fairborn, OH, USA", - ], + "2019_comps": { + "Miami Valley Regional 2019": "Fairborn, OH, USA", + }, "2019_awards": [], } } From ab5af8751663d21c27ecc321d4c7587885f58331 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Thu, 26 Sep 2019 20:21:15 -0700 Subject: [PATCH 08/23] Make output work for competiton locations --- ch_1_assign_kevin_rockwell.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ch_1_assign_kevin_rockwell.py b/ch_1_assign_kevin_rockwell.py index fffe853..8a5a1c5 100644 --- a/ch_1_assign_kevin_rockwell.py +++ b/ch_1_assign_kevin_rockwell.py @@ -6,6 +6,7 @@ "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", @@ -96,11 +97,16 @@ if requested_attribute not in valid_requests: print(f"Attribute {requested_attribute} not recognized.") requested_attribute = "" - -requested_attribute_value = teams[team_number][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) \ No newline at end of file From f6189aed6d559bc547e6ed51354c87de3ca9ae3e Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 2 Oct 2019 15:56:09 -0700 Subject: [PATCH 09/23] Add Ch 2 assignment --- ch_2_assign_kevin_rockwell.py | 162 ++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 ch_2_assign_kevin_rockwell.py diff --git a/ch_2_assign_kevin_rockwell.py b/ch_2_assign_kevin_rockwell.py new file mode 100644 index 0000000..eebaf8e --- /dev/null +++ b/ch_2_assign_kevin_rockwell.py @@ -0,0 +1,162 @@ +teams = {} + +def get_team_num(): + print("Enter team number or 'c' to cancel") + while True: + team_num = input("Team Number: ") + 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() + if vision == "t" or vision == "true": + return True + elif vision == "f" or vision == "false": + return False + elif vision == "": + return "" + 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 "" + 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 None + +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 None 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 + + 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 + save = input(f"Edit team {team_num}? [Y/n]").lower() + if save == "y" or save == "": + teams[team_num] = get_team_data() + break + elif save == "n": + break + + 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") \ No newline at end of file From 9c0d55300db8173b852784fe64f6514cc4bdab69 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 2 Oct 2019 18:46:05 -0700 Subject: [PATCH 10/23] Prevent already added teams from being readded --- ch_2_assign_kevin_rockwell.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ch_2_assign_kevin_rockwell.py b/ch_2_assign_kevin_rockwell.py index eebaf8e..17eca64 100644 --- a/ch_2_assign_kevin_rockwell.py +++ b/ch_2_assign_kevin_rockwell.py @@ -82,7 +82,8 @@ def get_team_data(): 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 From fd12e45c6769595cf10e1dbfd9b3093435960cac Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Thu, 3 Oct 2019 20:21:13 -0700 Subject: [PATCH 11/23] Make modify prompt for attributes --- ch_2_assign_kevin_rockwell.py | 44 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/ch_2_assign_kevin_rockwell.py b/ch_2_assign_kevin_rockwell.py index 17eca64..90abf41 100644 --- a/ch_2_assign_kevin_rockwell.py +++ b/ch_2_assign_kevin_rockwell.py @@ -3,7 +3,7 @@ def get_team_num(): print("Enter team number or 'c' to cancel") while True: - team_num = input("Team Number: ") + team_num = input("Team Number: ").lower().rstrip() if team_num.isdigit(): return int(team_num) elif team_num.lower() == "c": @@ -13,13 +13,13 @@ def get_team_num(): def get_vision(): while True: #Limit Vision to True or False - vision = input("Team Has Vision System [True/False]: ").lower() + 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 "" + return "Unknown" else: print(f"Invalid Value {vision}, expected True or False") @@ -29,7 +29,7 @@ def get_drivetrain_motors(): if motors.isdigit(): return int(motors) elif motors == "": - return "" + return "Unknown" else: print(f"Invalid Motor Number {motors}") @@ -39,7 +39,7 @@ def get_input(prompt): if response != "": return response else: - return None + return "Unknown" def print_team(team_num, team): print(f"Team {team_num} - {team['name']}\n") #Print Number - Name @@ -52,7 +52,7 @@ def print_team(team_num, team): 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 None using get_input + #Store Unknowns as "Unknown" using get_input temp_team["name"] = get_input("Team name:\n") temp_team["lang"] = get_input("Programming Language: ") @@ -87,7 +87,7 @@ def get_team_data(): temp_team = get_team_data() while True: #Confirm before saving - save = input(f"Save team {team_num}? [Y/n]").lower() + save = input(f"Save team {team_num}? [Y/n]").lower() if save == "y" or save == "": teams[team_num] = temp_team break @@ -105,12 +105,32 @@ def get_team_data(): continue print(f"Modifying team {team_num}") while True: #Confirm before saving - save = input(f"Edit team {team_num}? [Y/n]").lower() - if save == "y" or save == "": - teams[team_num] = get_team_data() - break - elif save == "n": + 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() From dfc0eebd99de420bbdb4b2a0c5a098b4f5b146b0 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 21:35:35 -0700 Subject: [PATCH 12/23] Add basic input functions and general program structure --- ch_3_assign_kevin_rockwell.py | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ch_3_assign_kevin_rockwell.py diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py new file mode 100644 index 0000000..16e7733 --- /dev/null +++ b/ch_3_assign_kevin_rockwell.py @@ -0,0 +1,57 @@ +from ch_1_assign_kevin_rockwell import teams + +def input_or_cancel(prompt): + i = input(prompt + ): + if i == "q": + return None + else: + return i + +def get_int(): + while True: + i = input_or_cancel("Please enter an integer or 'q' to cancel"): + if i is not None: + if i.isdigit(): + return int(i) + else: + print(f"Invalid input {i}") + continue + return i # user canceled, so return none + +while True: + #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 + pass + + elif selection == "v": #View team + pass + + elif selection == "m": #modify team + pass + + elif selection == "r": #remove team + pass + + elif selection == "s": #search for teams + pass + + elif selection == "l": #list teams + pass + + elif selection == "e": #exit program + pass + + else: + print(f"Invalid Action: {selection}\n") \ No newline at end of file From c48e12372bae5ae47e7a64b3c0aff2922274cb15 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 21:46:37 -0700 Subject: [PATCH 13/23] Fix input functions, rename get_int to get_positive_int - Rename makes clear what function actually does --- ch_3_assign_kevin_rockwell.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index 16e7733..9a28387 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -1,15 +1,15 @@ from ch_1_assign_kevin_rockwell import teams def input_or_cancel(prompt): - i = input(prompt + ): + i = input(prompt) if i == "q": return None else: return i -def get_int(): +def get_positive_int(): while True: - i = input_or_cancel("Please enter an integer or 'q' to cancel"): + i = input_or_cancel("Please enter a positive integer or 'q' to cancel") if i is not None: if i.isdigit(): return int(i) @@ -33,7 +33,12 @@ def get_int(): selection = "" selection = input("Action: ") if selection == "a": #Add team - pass + print("Enter team Number:") + team_num = get_positive_int() + if team_num in teams: + print(f"Team Number {team_num} already in teams") + continue + elif selection == "v": #View team pass From 93b1159f191dbfc121050fed2d900b6fa8171ee0 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 21:56:59 -0700 Subject: [PATCH 14/23] Add get_bool function --- ch_3_assign_kevin_rockwell.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index 9a28387..ec0bf02 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -9,7 +9,7 @@ def input_or_cancel(prompt): def get_positive_int(): while True: - i = input_or_cancel("Please enter a positive integer or 'q' to cancel") + i = input_or_cancel("Please enter a positive integer or 'q' to cancel: ") if i is not None: if i.isdigit(): return int(i) @@ -18,6 +18,20 @@ def get_positive_int(): continue return i # user canceled, so return none +def get_bool(): + while True: + i = input_or_cancel("Please enter (t)rue or (f)alse: ") + if i is not None: + i = i.lower() + if i in ["t", "true", "1", "y", "yes"]: + return True + elif i in ["f", "false", "0", "n", "no"]: + return False + else: + print(f"Invalid input {i}") + continue + return i # User canceled + while True: #Main Menu print(""" @@ -38,7 +52,10 @@ def get_positive_int(): if team_num in teams: print(f"Team Number {team_num} already in teams") continue - + elif team_num is None: + continue #User canceled, so exit add team and return to main menu + temp_team = {} + elif selection == "v": #View team pass From 4ce16914e50237de44f0907985a225463334c48d Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 22:08:48 -0700 Subject: [PATCH 15/23] Add attributes list, tweak wording in get_bool - Now asks for yes/no instead of true/false --- ch_3_assign_kevin_rockwell.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index ec0bf02..8cd43c3 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -20,7 +20,7 @@ def get_positive_int(): def get_bool(): while True: - i = input_or_cancel("Please enter (t)rue or (f)alse: ") + i = input_or_cancel("Please enter (y)es or (n)o: ") if i is not None: i = i.lower() if i in ["t", "true", "1", "y", "yes"]: @@ -30,7 +30,16 @@ def get_bool(): else: print(f"Invalid input {i}") continue - return i # User canceled + return i # User canceled + +attributes = [ + "location", + "rookie_year", + "competed_2019", + "2019_comps", + "comp_locations", + "2019_awards", + ] while True: #Main Menu From 8385a9948aeed19b4645c470c29f6bb9ed895746 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 22:59:15 -0700 Subject: [PATCH 16/23] Add get_comps and finish add team --- ch_3_assign_kevin_rockwell.py | 40 ++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index 8cd43c3..b5e4391 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -9,7 +9,7 @@ def input_or_cancel(prompt): def get_positive_int(): while True: - i = input_or_cancel("Please enter a positive integer or 'q' to cancel: ") + i = input_or_cancel("Enter a positive integer or 'q' to cancel: ") if i is not None: if i.isdigit(): return int(i) @@ -23,15 +23,37 @@ def get_bool(): i = input_or_cancel("Please enter (y)es or (n)o: ") if i is not None: i = i.lower() - if i in ["t", "true", "1", "y", "yes"]: + if i in ["t", "true", "1", "y", "yes"]: # Accept more truthy values return True - elif i in ["f", "false", "0", "n", "no"]: + elif i in ["f", "false", "0", "n", "no"]: # Same but for falsey return False else: print(f"Invalid input {i}") continue return i # User canceled +def get_comps(): + new_comps = {} + while True: + if comps == {}: + print("Add competition?") + else: + print("Add another competition?") + if not get_bool(): #User does not want to add more competitions + return comps + + name = input_or_cancel("Input Competition Name or 'q' to cancel:\n") + if name is None: + continue + elif name in new_comps: + print(f"Competition {name} already in list") + continue + + location = input_or_cancel("Input Location or 'q' to cancel:\n") + if location is None: + continue + comps[name] = location + attributes = [ "location", "rookie_year", @@ -64,7 +86,19 @@ def get_bool(): elif team_num is None: continue #User canceled, so exit add team and return to main menu temp_team = {} + temp_team["location"] = input_or_cancel("Input team location or" + + "'q' if unknown: ") # None for unknowns + print("Enter team rookie year") + temp_team["rookie_year"] = get_positive_int() + print("Enter if team competed in 2019") + temp_team["competed_2019"] = get_bool() + temp_team["2019_comps"] = get_comps() + temp_team["2019_awards"] = input_or_cancel("Enter 2019 awards or" + + "'q' if unknown") + print(f"Save team {team_num}") + if get_bool(): + teams[team_num] = temp_team elif selection == "v": #View team pass From 40f23629d0885d5cbc26df6ac7a5d1fe4dcec67d Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 23:02:31 -0700 Subject: [PATCH 17/23] Implement team deletion --- ch_3_assign_kevin_rockwell.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index b5e4391..a1fc693 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -107,7 +107,17 @@ def get_comps(): pass elif selection == "r": #remove team - pass + print("Input team number:") + team_num = get_positive_int() + if team_num is None: + continue + elif team_num not in teams: + print(f"Team Number {team_num} not stored.") + continue + + print(f"Delete team {team_num}?") + if get_bool(): + del teams[team_num] elif selection == "s": #search for teams pass From 54667dbbf01a58f33c8fb8fa68650c6393be93bf Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 23:03:48 -0700 Subject: [PATCH 18/23] Implement list teams (stolen from Ch 2) --- ch_3_assign_kevin_rockwell.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index a1fc693..9e78a9c 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -123,7 +123,19 @@ def get_comps(): pass elif selection == "l": #list teams - pass + 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 pass From cdc5285783d47b6358d92cef83ee1132004f6e87 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 23:07:16 -0700 Subject: [PATCH 19/23] Implement basic search - Only matches starts of (and complete) team number because team Name was not stored in the database --- ch_3_assign_kevin_rockwell.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index 9e78a9c..b78076e 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -120,7 +120,11 @@ def get_comps(): del teams[team_num] elif selection == "s": #search for teams - pass + print("Enter the start of or complete team number to search for:") + search_team = get_positive_int() + for t in teams: + if str(t).startswith(str(search_team)): + print(t) elif selection == "l": #list teams if len(teams.keys()) < 1: From 4399c799db87729c997322935b63ee4eb1e3ae95 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Tue, 15 Oct 2019 23:09:49 -0700 Subject: [PATCH 20/23] Implement exit --- ch_3_assign_kevin_rockwell.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index b78076e..3fc55c1 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -101,7 +101,7 @@ def get_comps(): teams[team_num] = temp_team elif selection == "v": #View team - pass + pass elif selection == "m": #modify team pass @@ -142,7 +142,9 @@ def get_comps(): print(" ".join(temp_ls)) elif selection == "e": #exit program - pass + print("Confirm Exit:") + if get_bool(): + break else: print(f"Invalid Action: {selection}\n") \ No newline at end of file From 326eee9dd9aec25f32bf5b05059e874699e56d34 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 16 Oct 2019 23:06:53 -0700 Subject: [PATCH 21/23] Implement modify, fix some stuff --- ch_3_assign_kevin_rockwell.py | 89 +++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/ch_3_assign_kevin_rockwell.py b/ch_3_assign_kevin_rockwell.py index 3fc55c1..94cbb26 100644 --- a/ch_3_assign_kevin_rockwell.py +++ b/ch_3_assign_kevin_rockwell.py @@ -1,4 +1,4 @@ -from ch_1_assign_kevin_rockwell import teams +teams = {} def input_or_cancel(prompt): i = input(prompt) @@ -33,11 +33,11 @@ def get_bool(): return i # User canceled def get_comps(): - new_comps = {} + comps = {} while True: - if comps == {}: + if comps == {}: # No comps have been, so add print("Add competition?") - else: + else: # Comps have been added, so add another comp print("Add another competition?") if not get_bool(): #User does not want to add more competitions return comps @@ -45,7 +45,7 @@ def get_comps(): name = input_or_cancel("Input Competition Name or 'q' to cancel:\n") if name is None: continue - elif name in new_comps: + elif name in comps: print(f"Competition {name} already in list") continue @@ -54,12 +54,28 @@ def get_comps(): continue comps[name] = location +def print_team(team, team_num): + print(f"Team Number {team_num}") + for a in attributes: + value = team.get(a) + if value is not None: + if a == "2019_comps": + print(a + ":") + if value == {}: + print(f"No stored competitions for {team_num}") + continue + for comp, location in value.items(): + print(f"{comp} in {location}") + continue + print(f"{a}: {value}") + else: + print(f"{a} is unknown for team {team_num}") + attributes = [ "location", "rookie_year", "competed_2019", "2019_comps", - "comp_locations", "2019_awards", ] @@ -87,24 +103,77 @@ def get_comps(): continue #User canceled, so exit add team and return to main menu temp_team = {} temp_team["location"] = input_or_cancel("Input team location or" - + "'q' if unknown: ") # None for unknowns + + " 'q' if unknown: ") # None for unknowns print("Enter team rookie year") temp_team["rookie_year"] = get_positive_int() print("Enter if team competed in 2019") temp_team["competed_2019"] = get_bool() temp_team["2019_comps"] = get_comps() temp_team["2019_awards"] = input_or_cancel("Enter 2019 awards or" - + "'q' if unknown") + + " 'q' if unknown\n") print(f"Save team {team_num}") if get_bool(): teams[team_num] = temp_team elif selection == "v": #View team - pass + print("Input team number: ") + team_num = get_positive_int() + if team_num not in teams: + print(f"Team Number {team_num} not stored.") + continue + elif team_num == None: + continue + print_team(teams[team_num], team_num) elif selection == "m": #modify team - pass + print("Input team number:") + team_num = get_positive_int() + if team_num is None: + continue + elif team_num not in teams: + print(f"Team number {team_num} not stored.") + continue + print("Current Values:") + print_team(teams[team_num], team_num) #Show current values + print(""" + Attribute to change: + (l)ocation + (r)ookie year + (c)ompetitions in 2019 + (i)f the team competed in 2019 + (a)wards won in 2019 + """) + while True: + i = input_or_cancel("Select attribute or 'q' to cancel: ") + if i in ["l", "r", "c", "i", "a", None]: + break + else: + print("Invalid attribute selection.") + if i == None: + continue + if i == "l": # Change location + location = input_or_cancel("Enter updated location or 'q' to cancel: ") + if location is not None: + teams[team_num]["location"] = location + elif i == "r": # Change rookie year + rookie = input_or_cancel("Enter updated rookie year or 'q' to cancel: ") + if rookie is not None: + teams[team_num]["rookie_year"] = rookie + elif i == "c": # Change 2019 competitions + print("Please enter all 2019 competitions. Enter no competitions to cancel") + comps = get_comps() + if comps != {}: + teams[team_num]["2019_comps"] = comps + elif i == "i": # Change competed 2019 + print("Enter if team competed in 2019 or 'q' to cancel") + comp_2019 = get_bool() + if comp_2019 is not None: + teams[team_num]["competed_2019"] = comp_2019 + elif i == "a": + awards = input_or_cancel("Enter 2019 awards or 'q' to cancel") + if awards is not None: + teams[team_num]["2019_awards"] = awards elif selection == "r": #remove team print("Input team number:") From 88ecee7a99cf691785d1c1bf76eabaa376b85098 Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Mon, 21 Oct 2019 16:05:01 -0700 Subject: [PATCH 22/23] Add Ch 4 Assignment --- ch_4_assign_kevin_rockwell.py | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ch_4_assign_kevin_rockwell.py diff --git a/ch_4_assign_kevin_rockwell.py b/ch_4_assign_kevin_rockwell.py new file mode 100644 index 0000000..c5279f5 --- /dev/null +++ b/ch_4_assign_kevin_rockwell.py @@ -0,0 +1,64 @@ +from math import hypot + +class Point(): + def __init__(self, x, y): + self.x, self.y = x, y + + def distance(self): + return hypot(self.x, self.y) + + +class Point_3D(Point): + def __init__(self, x, y, z): + super().__init__(x, y) + self.z = z + + def distance(self): + return hypot(super().distance(), self.z) + +def get_num(): + while True: + i = input("Enter a real number: ") + sign = "" + if i[0] in ["+", "-"]: # Has a sign as first value + sign = i[0] + i = i[1:] + decimal = False # Used to track if we've had a decimal point + for c in i: + if c not in "1234567890": + if c == "." and not decimal: + decimal = True + else: + print(f"Invalid input {i}") + break + else: + return float(sign + i) + +if __name__ == "__main__": + print("Enter x value for first point") + x = get_num() + print("Enter y value for first point") + y = get_num() + two_d = Point(x, y) + print("Enter x value for second point") + x = get_num() + print("Enter y value for second point") + y = get_num() + print("Enter z value for second point\n") + z = get_num() + three_d = Point_3D(x, y, z) + + + if two_d.distance() > three_d.distance(): + print("The first point is further from the origin") + elif two_d.distance() < three_d.distance(): + print("The second point is further from the origin") + else: + print("The two points are equally far from the origin") + + if two_d.distance() > Point.distance(three_d): + print("The second point is further from origin in x and y") + elif two_d.distance() < Point.distance(three_d): + print("The first point is further from origin in x and y") + else: + print("The two points are equally far from the origin in x and y") From 8238612af2d6e2a45f1901f9584b930d7c4b1b0d Mon Sep 17 00:00:00 2001 From: kevinrockwell Date: Wed, 23 Oct 2019 15:48:06 -0700 Subject: [PATCH 23/23] Add more comments to Ch 4 assignment --- ch_4_assign_kevin_rockwell.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ch_4_assign_kevin_rockwell.py b/ch_4_assign_kevin_rockwell.py index c5279f5..4a5a4d4 100644 --- a/ch_4_assign_kevin_rockwell.py +++ b/ch_4_assign_kevin_rockwell.py @@ -16,13 +16,14 @@ def __init__(self, x, y, z): def distance(self): return hypot(super().distance(), self.z) + def get_num(): while True: i = input("Enter a real number: ") sign = "" if i[0] in ["+", "-"]: # Has a sign as first value sign = i[0] - i = i[1:] + i = i[1:] #Number without the sign decimal = False # Used to track if we've had a decimal point for c in i: if c not in "1234567890": @@ -56,7 +57,7 @@ def get_num(): else: print("The two points are equally far from the origin") - if two_d.distance() > Point.distance(three_d): + if two_d.distance() > Point.distance(three_d): #Point to only use x and y print("The second point is further from origin in x and y") elif two_d.distance() < Point.distance(three_d): print("The first point is further from origin in x and y")