From d2b82722871d9f4bc2077c4c1ca407af8b77792b Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 11 Sep 2019 20:05:46 -0700 Subject: [PATCH 01/20] add Hello World --- ch_1_lesson_{Kathy}_{Li}.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 ch_1_lesson_{Kathy}_{Li}.py diff --git a/ch_1_lesson_{Kathy}_{Li}.py b/ch_1_lesson_{Kathy}_{Li}.py new file mode 100644 index 0000000..8c854ae --- /dev/null +++ b/ch_1_lesson_{Kathy}_{Li}.py @@ -0,0 +1 @@ +print('Hello, world!') \ No newline at end of file From 34049b2925d170b9690a5cef6d88f128cad007dd Mon Sep 17 00:00:00 2001 From: Kathy Date: Sun, 15 Sep 2019 20:27:15 -0700 Subject: [PATCH 02/20] ch_1_assign_kathy_li.py --- ch_1_assign_kathy_li.py | 110 ++++++++++++++++++++++++++++++++++++++++ sghwassignment1.py | 1 + 2 files changed, 111 insertions(+) create mode 100644 ch_1_assign_kathy_li.py create mode 100644 sghwassignment1.py diff --git a/ch_1_assign_kathy_li.py b/ch_1_assign_kathy_li.py new file mode 100644 index 0000000..e0ba45d --- /dev/null +++ b/ch_1_assign_kathy_li.py @@ -0,0 +1,110 @@ +#This is the dictionary that stores all the information about the teams. +teams_info = { + 1678 : { + 'location': 'Davis, California, USA', + 'rookie year': 2005, + 'competed in 2019?': True, + '2019 competitions': [ + 'Central Valley Regional (Fresno, California, USA)', + 'Sacramento Regional (Davis, California, USA)', + 'Aerospace Valley (Lancaster, California, USA)', + 'Carver Division - Houston Championship (Houston, Texas, USA)', + 'Einstein Field - Houston Championship (Houston, Texas, USA)', + 'RCC Qianjiang International Robotics Invitational (Hangzhou, Zhejiang, China)', + 'Chezy Champs (San Jose, California, USA)', + ], + '2019 season awards': [ + 'Chairman\'s Award, Central Valley Regional', + 'Winner, 2019 Central Valley Regional', + 'FIRST Dean\'s List Finalist Award, Sacramento Regional (Katie Stachowicz)', + 'Industrial Design Award (sponsored by General Motors), Sacramento Regional', + 'Winner, 2019 Sacramento Regional', + 'Excellence in Engineering Award (sponsored by Delphi), Aerospace Valley Regional', + 'Winner, 2019 Aerospace Valley Regional', + 'Entrepreneurship Award (sponsored by Kleiner Perkins Caufield and Byers)', + 'Winner, 2019 Carver Division - Houston Championship', + ] + }, + 1868 : { + 'location': 'Mountain View, California, USA', + 'rookie year': 2006, + 'competed in 2019?': True, + '2019 competitions': [ + 'Los Angeles North Regional (Valencia, California, USA)', + 'Silicon Valley Regional (San Jose, California, USA)', + 'Turing Division - Houston Championship (Houston, TX)', + 'Chezy Champs (San Jose, California, USA)', + ], + '2019 season awards': [ + 'Chairman\'s Award, Los Angeles North Regional', + 'Winner, 2019 Los Angeles North Regional', + 'Entrepreneurship Award (sponsored by Kleiner Perkins Caufield and Byers), Silicon Valley Regional', + ] + }, + 1323 : { + 'location': 'Madera, California, USA', + 'rookie year': 2004, + 'competed in 2019?': True, + '2019 competitions': [ + 'Central Valley Regional (Fresno, California, USA)', + 'Sacramento Regional (Davis, California, USA)', + 'Newton Division - Houston Championship (Houston, Texas, USA)', + 'Einstein Field (Houston, Texas, USA)', + ], + '2019 season awards': [ + 'Autonomous Award (sponsored by Ford), Central Valley Regional', + 'Winner, 2019 Central Valley Regional', + 'Quality Award sponsored by Motorola Solutions Foundation', + 'Winner, 2019 Sacramento Regional', + 'Industrial Design Award (sponsored by General Motors), Houston Championship ' + 'Winner, 2019 Newton Division - Houston Championship', + 'Winner, 2019 Houston Championship', + ] + }, + 3132 : { + 'location': 'Sydney, Australia', + 'rookie year': 2010, + 'competed in 2019?': True, + '2019 competitions': [ + 'Southern Cross Regional (Sydney, Australia)', + 'South Pacific Regional (Sydney, Australia)', + 'Carver Division - Houston Championship (Houston, Texas, USA)', + 'Einstein Field - Houston Championship (Houston, Texas, USA)', + 'Duel Down Under (Sydney, Australia)', + ], + '2019 season awards': [ + 'Woodie Flowers Finalist Award, Southern Cross Regional (Sarah Heimlich)', + 'Gracious Professionalism Award (sponsored by Johnson & Johnson), Southern Cross Regional', + 'Regional Engineering Inspiration Award, South Pacific Regional', + 'FIRST Dean\'s List Finalist Award, South Pacific Regional (Jaye Heimlich)', + 'Safety Award (sponsored by Underwriters Laboratories), South Pacific Regional', + 'Winner, 2019 Carver Division - Houston Championship', + ] + }, + 254 : { + 'location': 'San Jose, California, USA', + 'rookie year': 1999, + 'competed in 2019?': True, + '2019 competitions': [ + 'San Francisco Regional (San Francisco, California, USA)', + 'Silicon Valley Regional (San Jose, California, USA)', + 'Turing Division - Houston Championship (Houston, Texas, USA)', + 'Einstein Field - Houston Championship (Houston, Texas, USA)', + 'Chezy Champs (San Jose, California, USA)' + ], + '2019 season awards': [ + 'Innovation in Control Award (sponsored by Rockwell Automation), San Francisco Regional', + 'Winner, 2019 San Francisco Regional', + 'Excellence in Engineering Award (sponsored by Delphi), Silicon Valley Regional', + 'Winner, 2019 Silicon Valley Regional', + 'Industrial Design Award (sponsored by General Motors), Turing Divions' + 'Winner, 2019 Turing Division - Houston Championship', + 'Championship Finalist, Einstein Field - Houston Championship', + + ] + }, +} +team_input = int(input('Choose an FRC team: 1678, 1868, 1323, 3132, or 254.\n')) +team_attribute = str(input('Enter an attribute: "Location", "Rookie Year", "Competed in 2019?", "2019 Competitions", and "2019 Season Awards".\n').lower()) +#without .lower(), user input is case-sensitive. +print(teams_info[team_input][team_attribute]) \ No newline at end of file diff --git a/sghwassignment1.py b/sghwassignment1.py new file mode 100644 index 0000000..edc3e59 --- /dev/null +++ b/sghwassignment1.py @@ -0,0 +1 @@ +teams_and_robots = {team_1678 = {'weight':'167','wheels':'hexagonal','length':'20','width':'9','color':'neon yellow'}} \ No newline at end of file From 6701a397072c953c628c9628934973b92cb56331 Mon Sep 17 00:00:00 2001 From: Kathy Date: Sun, 15 Sep 2019 20:32:31 -0700 Subject: [PATCH 03/20] ch_1_assign_kathy_li.py --- sghwassignment1.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 sghwassignment1.py diff --git a/sghwassignment1.py b/sghwassignment1.py deleted file mode 100644 index edc3e59..0000000 --- a/sghwassignment1.py +++ /dev/null @@ -1 +0,0 @@ -teams_and_robots = {team_1678 = {'weight':'167','wheels':'hexagonal','length':'20','width':'9','color':'neon yellow'}} \ No newline at end of file From 9c37602636f3b99de2cb3eceb6b2312869798732 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 2 Oct 2019 16:45:22 -0700 Subject: [PATCH 04/20] Add existing file --- ch_2_assign_kathy_li.py | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 ch_2_assign_kathy_li.py diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py new file mode 100644 index 0000000..0e30bb9 --- /dev/null +++ b/ch_2_assign_kathy_li.py @@ -0,0 +1,82 @@ +teams = {} +user_action = input("Welcome to the Menu. Please select an action: add, remove, modify, view team information, search, or list. To quit, enter quit.") +while True: + + if user_action == "list": + print(teams) + return + + elif user_action == "remove": + delete_team_input = int(input("Which team would you like to remove? Enter 0 to return to the main menu.")) + if delete_team_input == "0": + return + elif delete_team_input in teams.keys(): + teams.pop(delete_team_input) + print("Team " + delete_team_input + " has been removed.") + else: + print("Team " + delete_team_input " has not been found. Returning to main menu...") + return + +# elif user_action == "modify": +# update_team_input = input("which team would you like to modify?") +# if update_team_input in teams.keys(): +# print(teams[update_team_input]) +# area_of_update_team = input("Which area of the team would you like to update?") + +#This below chunk of code is error message debugger code that I haven't finished yet. + +# if area_of_update_team in ["new_team", "new_team_robot_width", "new_team_robot_length", "new_team_drivetrain_motors"]: +# update_value = input("New value: ") +# if not area_of_update_team.isnumeric(): +# print("Input is not valid.") +# elif area_of_update_team == "new_team_camera_vision": +# if value.lower() != "yes" and value.lower() != "no": +# +# +# +# else: +# teams[update_team_input][area_of_update_team] = value +# print("The team has been updated.") + + + elif user_action == "add": + new_team = int(input("Enter the number of the team you want to add.")) + teams[new_team] = {} + new_team_name = input("What is the team's name?") + teams[new_team]["name"] = new_team_name + new_team_programming_language = input("What programming language does the team use?") + teams[new_team]["programming language"] = new_team_programming_language + new_team_robot_width = input("What is the width of the team's robot?") + teams[new_team_name]["width of robot"] = new_team_robot_width + new_team_robot_length = int(input("What is the length of the team's robot?")) + teams[new_team_name]["length of robot"] = new_team_robot_length + new_team_camera_vision = int(input("Does the team have a camera vision system?")) + teams[new_team_name]["camera vision"] = new_team_camera_vision + new_team_number_of_drivetrain_motors = input("How many drivetrain motors does the robot have?") + teams[new_team]["number of drivetrain motors"] = new_team_number_of_drivetrain_motors + print("Returning to main menu...") + return + + elif user_action == "view team information": + view_team_input = input("Which team's information would you like to view? To return to the menu, press 0.") + if view_team_input == "0": + return + elif view_team_input in teams(): + print(teams[view_team_input]) + else: + print("Team" + view_team_input + " has not been found. Returning to main menu...") + return + + elif user_action == "search": + search_team_input = input("Which team would you like to search for? To return to the main menu, enter 0.") + if search_team_input in teams.keys(): + print(teams[search_team_input]) + else + print("Team does not exist. Returning to main menu...") + break + + elif user_action == "quit": + break +#To not receive an error message in the add function, could I define each variable seperately and make an if/else/elif statement? +#Can I loop the code instead of making it return to the main menu? +#Have not tested entire code/done validation yet. \ No newline at end of file From d1aeea4e66b9cb564251a5affc453f0834d551ad Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 2 Oct 2019 20:47:31 -0700 Subject: [PATCH 05/20] second draft; body of code completed and mostly functioning --- ch_2_assign_kathy_li.py | 88 ++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index 0e30bb9..1e5ad32 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -4,23 +4,28 @@ if user_action == "list": print(teams) - return + continue elif user_action == "remove": - delete_team_input = int(input("Which team would you like to remove? Enter 0 to return to the main menu.")) - if delete_team_input == "0": - return - elif delete_team_input in teams.keys(): - teams.pop(delete_team_input) - print("Team " + delete_team_input + " has been removed.") + delete_team = int(input("Which team would you like to remove? Enter 0 to continue to the main menu.")) + if delete_team == "0": + continue + elif delete_team in teams.keys(): + teams.pop(delete_team) + print("Team " + delete_team + " has been removed.") else: - print("Team " + delete_team_input " has not been found. Returning to main menu...") - return + print("Team " + delete_team + " has not been found. Returning to main menu...") + continue -# elif user_action == "modify": -# update_team_input = input("which team would you like to modify?") -# if update_team_input in teams.keys(): -# print(teams[update_team_input]) + elif user_action == "modify": + update_team = input("Which team would you like to modify?" ) + update_variable = input("Which field would you like to modify? ") + change = input("Enter the new value. ") + if update_team_input in teams.keys(): + teams[update_team][update_variable] = change + else: + print("Team " + update_team + " was not found. Returning to main menu...") + continue # area_of_update_team = input("Which area of the team would you like to update?") #This below chunk of code is error message debugger code that I haven't finished yet. @@ -30,7 +35,8 @@ # if not area_of_update_team.isnumeric(): # print("Input is not valid.") # elif area_of_update_team == "new_team_camera_vision": -# if value.lower() != "yes" and value.lower() != "no": +# if value != "yes" and value != "no": + # # # @@ -42,41 +48,43 @@ elif user_action == "add": new_team = int(input("Enter the number of the team you want to add.")) teams[new_team] = {} - new_team_name = input("What is the team's name?") - teams[new_team]["name"] = new_team_name - new_team_programming_language = input("What programming language does the team use?") - teams[new_team]["programming language"] = new_team_programming_language - new_team_robot_width = input("What is the width of the team's robot?") - teams[new_team_name]["width of robot"] = new_team_robot_width - new_team_robot_length = int(input("What is the length of the team's robot?")) - teams[new_team_name]["length of robot"] = new_team_robot_length - new_team_camera_vision = int(input("Does the team have a camera vision system?")) - teams[new_team_name]["camera vision"] = new_team_camera_vision - new_team_number_of_drivetrain_motors = input("How many drivetrain motors does the robot have?") - teams[new_team]["number of drivetrain motors"] = new_team_number_of_drivetrain_motors + name = input("What is the team's name?") + teams[new_team]["name"] = name + language = input("What programming language does the team use?") + teams[new_team]["programming language"] = language + width = input("What is the width of the team's robot?") + teams[new_team]["width of robot"] = width + length = int(input("What is the length of the team's robot?")) + teams[new_team]["length of robot"] = length + camera_vision = input("Does the team have a camera vision system?") + teams[new_team]["camera vision"] = camera_vision + drivetrain_motors = input("How many drivetrain motors does the robot have?") + teams[new_team]["number of drivetrain motors"] = drivetrain_motors print("Returning to main menu...") - return + continue elif user_action == "view team information": - view_team_input = input("Which team's information would you like to view? To return to the menu, press 0.") - if view_team_input == "0": - return - elif view_team_input in teams(): - print(teams[view_team_input]) + view_input = input("Which team's information would you like to view? To continue to the menu, press 0.") + if view_input == "0": + continue + elif view_input in teams(): + print(teams[view_input]) else: - print("Team" + view_team_input + " has not been found. Returning to main menu...") - return + print("Team" + view_input + " has not been found. Returning to main menu...") + continue elif user_action == "search": - search_team_input = input("Which team would you like to search for? To return to the main menu, enter 0.") - if search_team_input in teams.keys(): - print(teams[search_team_input]) - else + search_input = input("Which team would you like to search for? To return to the main menu, enter 0.") + if search_input == "0": + continue + elif search_input in teams.keys(): + print(teams[search_input]) + else: print("Team does not exist. Returning to main menu...") break elif user_action == "quit": break #To not receive an error message in the add function, could I define each variable seperately and make an if/else/elif statement? -#Can I loop the code instead of making it return to the main menu? -#Have not tested entire code/done validation yet. \ No newline at end of file +#Can I loop the code instead of making it continue to the main menu? +#Have not tested entire code/done validation yet. \ No newline at end of file From 5935cb1d528aeeaf538d8c05ce2c6958532e04c6 Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 3 Oct 2019 20:46:35 -0700 Subject: [PATCH 06/20] Add verification. --- ch_2_assign_kathy_li.py | 91 +++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index 1e5ad32..bc4d14e 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -1,30 +1,31 @@ teams = {} -user_action = input("Welcome to the Menu. Please select an action: add, remove, modify, view team information, search, or list. To quit, enter quit.") while True: - + user_action = input("Welcome to the menu. Please select an action: add, remove, modify, view, search, or list. To quit, enter quit.") if user_action == "list": print(teams) continue - + #note to self: validation to do - "list" with no teams inside prints infinite teams elif user_action == "remove": - delete_team = int(input("Which team would you like to remove? Enter 0 to continue to the main menu.")) - if delete_team == "0": + delete_team = int(input("Which team would you like to remove? Enter 0 to return to the main menu.")) + if delete_team == 0: continue elif delete_team in teams.keys(): teams.pop(delete_team) - print("Team " + delete_team + " has been removed.") + print("Team " + str(delete_team) + " has been removed.") else: - print("Team " + delete_team + " has not been found. Returning to main menu...") + print("Team " + str(delete_team) + " has not been found. Returning to main menu...") continue elif user_action == "modify": - update_team = input("Which team would you like to modify?" ) - update_variable = input("Which field would you like to modify? ") - change = input("Enter the new value. ") - if update_team_input in teams.keys(): + update_team = int(input("Which team would you like to modify? To return the to the main menu, enter 0." )) + if update_team == 0: + continue + if update_team in teams.keys(): + update_variable = input("Which field would you like to modify? ") + change = input("Enter the new value. ") teams[update_team][update_variable] = change else: - print("Team " + update_team + " was not found. Returning to main menu...") + print("Team " + str(update_team) + " was not found. Returning to main menu...") continue # area_of_update_team = input("Which area of the team would you like to update?") @@ -46,41 +47,59 @@ elif user_action == "add": - new_team = int(input("Enter the number of the team you want to add.")) - teams[new_team] = {} - name = input("What is the team's name?") - teams[new_team]["name"] = name - language = input("What programming language does the team use?") - teams[new_team]["programming language"] = language - width = input("What is the width of the team's robot?") - teams[new_team]["width of robot"] = width - length = int(input("What is the length of the team's robot?")) - teams[new_team]["length of robot"] = length - camera_vision = input("Does the team have a camera vision system?") - teams[new_team]["camera vision"] = camera_vision - drivetrain_motors = input("How many drivetrain motors does the robot have?") - teams[new_team]["number of drivetrain motors"] = drivetrain_motors - print("Returning to main menu...") - continue + new_team = input("Enter the number of the team you want to add. To return to the main menu, enter 0. ") + if not new_team.isnumeric(): + print("Must be a number. Returning to main menu... ") + continue + elif new_team == 0: + continue + else: + new_team = int(new_team) + teams[new_team] = {} + teams[new_team]["name"] = input("What is the team's name? ") + teams[new_team]["programming language"] = input("What programming language does the team use? ") + width = input("What is the width of the team's robot? ") + if not width.isnumeric(): + print("Width must be a number. Returning to main menu... ") + continue + else: + width = float(width) + teams[new_team]["width of robot"] = width + length = input("What is the length of the team's robot? ") + if not length.isnumeric(): + print("Length must be a number. Returning to main menu... ") + continue + else: + length = float(width) + teams[new_team]["length of robot"] = length + teams[new_team]["camera vision"] = input("Does the team have a camera vision system? ") + drivetrain_motors = input("How many drivetrain motors does the robot have? ") + if not drivetrain_motors.isnumeric(): + print("Drivetrain motors must be a number. Returning to main menu... ") + continue + else: + teams[new_team]["number of drivetrain motors"] = drivetrain_motors + print("Team added. Returning to main menu... ") + continue - elif user_action == "view team information": - view_input = input("Which team's information would you like to view? To continue to the menu, press 0.") - if view_input == "0": + elif user_action == "view": + view_input = int(input("Which team's information would you like to view? To continue to the menu, press 0. ")) + if view_input == 0: continue - elif view_input in teams(): + elif view_input in teams: print(teams[view_input]) else: - print("Team" + view_input + " has not been found. Returning to main menu...") + print("Team " + view_input + " has not been found. Returning to main menu... ") continue elif user_action == "search": - search_input = input("Which team would you like to search for? To return to the main menu, enter 0.") - if search_input == "0": + search_input = int(input("Which team would you like to search for? To return to the main menu, enter 0. ")) + if search_input == 0: continue elif search_input in teams.keys(): print(teams[search_input]) else: - print("Team does not exist. Returning to main menu...") + print("Team does not exist. Returning to main menu... ") break elif user_action == "quit": From 44ee300dcaa678ae081f8de0d087f1bbdcbfede7 Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 4 Oct 2019 00:01:10 -0700 Subject: [PATCH 07/20] Add final validation. --- ch_2_assign_kathy_li.py | 122 ++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index bc4d14e..048ee11 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -1,109 +1,121 @@ teams = {} while True: - user_action = input("Welcome to the menu. Please select an action: add, remove, modify, view, search, or list. To quit, enter quit.") + user_action = input("Welcome to the menu. Please select an action: add, remove, modify, view, search, or list. To quit, enter quit. \n") + if user_action == "list": print(teams) continue - #note to self: validation to do - "list" with no teams inside prints infinite teams + elif user_action == "remove": - delete_team = int(input("Which team would you like to remove? Enter 0 to return to the main menu.")) + delete_team = int(input("Which team would you like to remove? Enter 0 to return to the menu. \n")) if delete_team == 0: continue elif delete_team in teams.keys(): teams.pop(delete_team) - print("Team " + str(delete_team) + " has been removed.") + print("Team " + str(delete_team) + " has been removed. Returning to menu... ") + continue else: - print("Team " + str(delete_team) + " has not been found. Returning to main menu...") + print("Team " + str(delete_team) + " has not been found. Returning to menu... ") continue elif user_action == "modify": - update_team = int(input("Which team would you like to modify? To return the to the main menu, enter 0." )) + update_team = int(input("Which team would you like to modify? To return the to the menu, enter 0. \n ")) if update_team == 0: continue - if update_team in teams.keys(): - update_variable = input("Which field would you like to modify? ") - change = input("Enter the new value. ") - teams[update_team][update_variable] = change + elif update_team in teams.keys(): + update_variable = input("Which field would you like to modify: name, programming language, width, length, number of drivetrain motors, or camera vision? \n") + if update_variable not in teams[new_team].keys(): + print("There is no such field. Returning to menu... ") + continue + change = input("Enter the new value. \n") + if update_variable in ["width", "length", "number of drivetrain motors"]: + if not change.isnumeric(): + print("Input is invalid. Returning to menu... ") + continue + else: + teams[update_team][update_variable] = change + print("Successfully changed. Returning to menu... ") + continue + elif update_variable == "camera vision": + change = bool(change) + if not change == True or change == False: + print("Please input True or False. Returning to menu... ") + continue + else: + teams[update_team][update_variable] = change + print("Successfully changed. Returning to menu... ") + else: + teams[update_team][update_variable] = change + print("Successfully changed. Returning to menu... ") + continue else: - print("Team " + str(update_team) + " was not found. Returning to main menu...") + print("Team " + str(update_team) + " was not found. Returning to menu... ") continue -# area_of_update_team = input("Which area of the team would you like to update?") - -#This below chunk of code is error message debugger code that I haven't finished yet. - -# if area_of_update_team in ["new_team", "new_team_robot_width", "new_team_robot_length", "new_team_drivetrain_motors"]: -# update_value = input("New value: ") -# if not area_of_update_team.isnumeric(): -# print("Input is not valid.") -# elif area_of_update_team == "new_team_camera_vision": -# if value != "yes" and value != "no": - -# -# -# -# else: -# teams[update_team_input][area_of_update_team] = value -# print("The team has been updated.") - elif user_action == "add": - new_team = input("Enter the number of the team you want to add. To return to the main menu, enter 0. ") + new_team = input("Enter the number of the team you want to add. To return to the menu, enter 0. \n") if not new_team.isnumeric(): - print("Must be a number. Returning to main menu... ") + print("Must be a number. Returning to menu... ") continue elif new_team == 0: continue else: new_team = int(new_team) teams[new_team] = {} - teams[new_team]["name"] = input("What is the team's name? ") - teams[new_team]["programming language"] = input("What programming language does the team use? ") - width = input("What is the width of the team's robot? ") + teams[new_team]["name"] = input("What is the team's name? \n") + teams[new_team]["programming language"] = input("What programming language does the team use? \n") + width = input("What is the width of the team's robot? \n") if not width.isnumeric(): - print("Width must be a number. Returning to main menu... ") + print("Width must be a number. Returning to menu... ") continue else: width = float(width) - teams[new_team]["width of robot"] = width - length = input("What is the length of the team's robot? ") + teams[new_team]["width"] = width + length = input("What is the length of the team's robot? \n") if not length.isnumeric(): - print("Length must be a number. Returning to main menu... ") + print("Length must be a number. Returning to menu... ") continue else: length = float(width) - teams[new_team]["length of robot"] = length - teams[new_team]["camera vision"] = input("Does the team have a camera vision system? ") - drivetrain_motors = input("How many drivetrain motors does the robot have? ") + teams[new_team]["length"] = length + camera_vision = input("Does the team have a camera vision system? Input True or False. \n") + camera_vision = bool(camera_vision) + if not camera_vision == True or camera_vision == False: + print("Please follow directions. Returning to menu... ") + continue + else: + teams[new_team]["camera vision"] = camera_vision + drivetrain_motors = input("How many drivetrain motors does the robot have? \n") if not drivetrain_motors.isnumeric(): - print("Drivetrain motors must be a number. Returning to main menu... ") + print("Drivetrain motors must be a number. Returning to menu... ") continue else: teams[new_team]["number of drivetrain motors"] = drivetrain_motors - print("Team added. Returning to main menu... ") + print("Team added. Returning to menu... ") continue elif user_action == "view": - view_input = int(input("Which team's information would you like to view? To continue to the menu, press 0. ")) - if view_input == 0: + view_input = input("Which team's information would you like to view? To return to the menu, press 0. \n") + if not view_input.isnumeric(): + print("Team must be a number. Returning to menu... ") + continue + elif view_input == int(0): continue + view_input = int(view_input) elif view_input in teams: print(teams[view_input]) + continue else: - print("Team " + view_input + " has not been found. Returning to main menu... ") + print("Team " + view_input + " has not been found. Returning to menu... ") continue - elif user_action == "search": - search_input = int(input("Which team would you like to search for? To return to the main menu, enter 0. ")) + search_input = int(input("Which team would you like to search for? To return to the menu, enter 0. \n")) if search_input == 0: continue elif search_input in teams.keys(): print(teams[search_input]) else: - print("Team does not exist. Returning to main menu... ") - break - + print("Team does not exist. Returning to menu... ") + continue elif user_action == "quit": - break -#To not receive an error message in the add function, could I define each variable seperately and make an if/else/elif statement? -#Can I loop the code instead of making it continue to the main menu? -#Have not tested entire code/done validation yet. \ No newline at end of file + break \ No newline at end of file From e8a827301489f18c7168cd22f98a2657a819ee53 Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 4 Oct 2019 00:17:53 -0700 Subject: [PATCH 08/20] Add final validation. --- ch_2_assign_kathy_li.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index 048ee11..6255d60 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -57,7 +57,7 @@ if not new_team.isnumeric(): print("Must be a number. Returning to menu... ") continue - elif new_team == 0: + elif new_team == "0": continue else: new_team = int(new_team) @@ -99,9 +99,8 @@ if not view_input.isnumeric(): print("Team must be a number. Returning to menu... ") continue - elif view_input == int(0): + elif view_input == 0: continue - view_input = int(view_input) elif view_input in teams: print(teams[view_input]) continue From 10eee12d24cb2feaf4ff7911954fbbc796b30902 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 9 Oct 2019 19:36:05 -0700 Subject: [PATCH 09/20] Edit more. --- ch_2_assign_kathy_li.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index 6255d60..92dd41e 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -99,7 +99,10 @@ if not view_input.isnumeric(): print("Team must be a number. Returning to menu... ") continue - elif view_input == 0: + + view_input = int(view_input) + + if view_input == 0: continue elif view_input in teams: print(teams[view_input]) From dede2efdee4b66ff74b93dfb9535c3f676099cc1 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 16 Oct 2019 23:37:07 -0700 Subject: [PATCH 10/20] add function --- ch_3_assign_kathy_li.py | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 ch_3_assign_kathy_li.py diff --git a/ch_3_assign_kathy_li.py b/ch_3_assign_kathy_li.py new file mode 100644 index 0000000..2227ceb --- /dev/null +++ b/ch_3_assign_kathy_li.py @@ -0,0 +1,116 @@ +teams = {} + +def master_action(): + while True: + user_action = input("Welcome to the menu. Please select an action: add, remove, modify, view, search, or list. To quit, enter quit. \n") + if user_action == "list": + list_teams() + elif user_action == "remove": + remove_team() + elif user_action == "search": + search_team() + elif user_action == "add": + add_team() + elif user_action == "modify": + modify_team() + elif user_action == "view": + view_team() + elif user_action == "quit": + quit_program() + +def list_teams(): + print(teams) + +def remove_team(): + delete_team = int(input("Which team would you like to remove? \n")) + if delete_team in teams.keys(): + teams.pop(delete_team) + print("Team " + str(delete_team) + " has been removed. Returning to menu... ") + else: + print("Team " + str(delete_team) + " has not been found. Returning to menu... ") + +def search_team(): + search_input = int(input("Which team would you like to search for? \n")) + if search_input in teams.keys(): + print(teams[search_input]) + else: + print("Team does not exist. Returning to menu... ") + +def add_team(): + new_team = input("Enter the number of the team you want to add. \n") + if new_team.isnumeric() == False: + print("Must be a number. Returning to menu... ") + else: + new_team = int(new_team) + teams[new_team] = {} + teams[new_team]["name"] = input("What is the team's name? \n") + + teams[new_team]["location"] = input("Where is the team located? \n") + + rookie_year = input("What is the team's rookie year? \n") + if not rookie_year.isnumeric(): + print("Rookie year must be a number. Returning to menu... ") + else: + rookie_year = int(rookie_year) + teams[new_team]["rookie year"] = rookie_year + + competed_in_2019 = input("Did they compete in 2019? Input True or False. \n") + competed_in_2019 = bool(competed_in_2019) + if not competed_in_2019 == True or competed_in_2019 == False: + print("Please follow directions. Returning to menu... ") + master_action() + elif competed_in_2019 == False: + print("Information added, returning to menu.") + else: + teams[new_team]["competed in 2019"] = competed_in_2019 + + teams[new_team]["2019 competitions"] = input("What were their 2019 competitions? \n") + teams[new_team]["2019 awards"] = input("What awards did they receive in 2019? \n") + print("Team added. Returning to menu... ") + +def view_team(): + view_input = input("Which team's information would you like to view? \n") + if not view_input.isnumeric(): + print("Team must be a number. Returning to menu... ") + view_input = int(view_input) + if view_input in teams: + print(teams[view_input]) + else: + print("Team " + view_input + " has not been found. Returning to menu... ") + +def modify_team(): + update_team = int(input("Which team would you like to modify? To return the to the menu, enter 0. \n ")) + if update_team in teams.keys(): + update_variable = input("Which field would you like to modify: name, location, rookie year, compteted in 2019, 2019 competitions, or 2019 awards? \n") + if update_variable not in teams[update_team].keys(): + print("There is no such field. Returning to menu... ") + + change = input("Enter the new value. \n") + if update_variable == "rookie year": + if not change.isnumeric(): + print("Input is invalid. Returning to menu... ") + + else: + teams[update_team][update_variable] = change + print("Successfully changed. Returning to menu... ") + + elif update_variable == "competed in 2019": + change = bool(change) + if not change == True or change == False: + print("Please input True or False. Returning to menu... ") + + else: + teams[update_team][update_variable] = change + print("Successfully changed. Returning to menu... ") + else: + teams[update_team][update_variable] = change + print("Successfully changed. Returning to menu... ") + + else: + print("Team " + str(update_team) + " was not found. Returning to menu... ") + +def quit_program(): + ##break + print("Use Ctrl-C to exit the program.") + +master_action() \ No newline at end of file From 871e5136e0e0c50d18db95f4b53e730edb33c55a Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 16 Oct 2019 23:50:00 -0700 Subject: [PATCH 11/20] Add function --- ch_1_assign_kathy_li.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ch_1_assign_kathy_li.py b/ch_1_assign_kathy_li.py index e0ba45d..931fc94 100644 --- a/ch_1_assign_kathy_li.py +++ b/ch_1_assign_kathy_li.py @@ -1,6 +1,6 @@ #This is the dictionary that stores all the information about the teams. teams_info = { - 1678 : { + 1678: { 'location': 'Davis, California, USA', 'rookie year': 2005, 'competed in 2019?': True, @@ -25,7 +25,7 @@ 'Winner, 2019 Carver Division - Houston Championship', ] }, - 1868 : { + 1868: { 'location': 'Mountain View, California, USA', 'rookie year': 2006, 'competed in 2019?': True, @@ -41,7 +41,7 @@ 'Entrepreneurship Award (sponsored by Kleiner Perkins Caufield and Byers), Silicon Valley Regional', ] }, - 1323 : { + 1323: { 'location': 'Madera, California, USA', 'rookie year': 2004, 'competed in 2019?': True, @@ -61,7 +61,7 @@ 'Winner, 2019 Houston Championship', ] }, - 3132 : { + 3132: { 'location': 'Sydney, Australia', 'rookie year': 2010, 'competed in 2019?': True, @@ -81,7 +81,7 @@ 'Winner, 2019 Carver Division - Houston Championship', ] }, - 254 : { + 254: { 'location': 'San Jose, California, USA', 'rookie year': 1999, 'competed in 2019?': True, @@ -105,6 +105,6 @@ }, } team_input = int(input('Choose an FRC team: 1678, 1868, 1323, 3132, or 254.\n')) -team_attribute = str(input('Enter an attribute: "Location", "Rookie Year", "Competed in 2019?", "2019 Competitions", and "2019 Season Awards".\n').lower()) +team_attribute = input('Enter an attribute: "Location", "Rookie Year", "Competed in 2019?", "2019 Competitions", and "2019 Season Awards".\n').lower() #without .lower(), user input is case-sensitive. print(teams_info[team_input][team_attribute]) \ No newline at end of file From 9f86ac9c6bcf7e228f1f5e76070fc5008d1338b9 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 30 Oct 2019 18:46:12 -0700 Subject: [PATCH 12/20] Add code --- ch_4_assign_kathy_li.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ch_4_assign_kathy_li.py diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py new file mode 100644 index 0000000..55f6c54 --- /dev/null +++ b/ch_4_assign_kathy_li.py @@ -0,0 +1,26 @@ +import math +class Point: + def __init__ (self, x, y): + self.x = x + self.y = y + + def distance(self): + return math.sqrt(x**2 + y**2) + +class Point_3D(Point): + def __init__ (self, x, y, z): + super().__init__(x, y) + self.z = z + + def distance(self): + return math.sqrt(x**2 + y**2 + z**2) + +x = int(input("What is the x-value of your point? \n" )) +y = int(input("what is the y-value of your point? \n")) +point = Point(x, y) +print(point.distance()) + +z = int(input("What is the z-value of your point? \n")) +point = Point_3D(x, y, z) +print(point.distance()) + From c1e8d4251fd2c9a9c8cdff33a13eba9a1c83dc4c Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 30 Oct 2019 20:08:59 -0700 Subject: [PATCH 13/20] Update code --- ch_4_assign_kathy_li.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py index 55f6c54..bee882f 100644 --- a/ch_4_assign_kathy_li.py +++ b/ch_4_assign_kathy_li.py @@ -22,5 +22,4 @@ def distance(self): z = int(input("What is the z-value of your point? \n")) point = Point_3D(x, y, z) -print(point.distance()) - +print(point.distance()) \ No newline at end of file From 35e5351434ab78ca04432954c7ff354f18d5cd8c Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 30 Oct 2019 20:35:22 -0700 Subject: [PATCH 14/20] update code --- ch_4_assign_kathy_li.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py index bee882f..3ba585f 100644 --- a/ch_4_assign_kathy_li.py +++ b/ch_4_assign_kathy_li.py @@ -17,9 +17,16 @@ def distance(self): x = int(input("What is the x-value of your point? \n" )) y = int(input("what is the y-value of your point? \n")) -point = Point(x, y) -print(point.distance()) +point_a = Point(x, y) +print("The distance from the origin is " + str(point_a.distance())) z = int(input("What is the z-value of your point? \n")) -point = Point_3D(x, y, z) -print(point.distance()) \ No newline at end of file +point_b = Point_3D(x, y, z) +print("The distance from the origin is " + str(point_b.distance())) + +if point_a.distance() > point_b.distance(): + print("The 2D point is further from the origin than the 3D point.") +elif point_b.distance() > point_a.distance(): + print("The 3D point is further from the origin than the 2D point.") +elif point_a.distance() == point_b.distance(): + print("The points are the same length.") \ No newline at end of file From 03f6c3108dd8c3e34880ccb8aa46ae35354ac85b Mon Sep 17 00:00:00 2001 From: Kathy Date: Sat, 2 Nov 2019 17:59:05 -0700 Subject: [PATCH 15/20] add validation --- ch_2_assign_kathy_li.py | 91 +++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index 92dd41e..22414ce 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -12,50 +12,56 @@ continue elif delete_team in teams.keys(): teams.pop(delete_team) - print("Team " + str(delete_team) + " has been removed. Returning to menu... ") + print("Team " + str(delete_team) + " has been removed. ") continue else: - print("Team " + str(delete_team) + " has not been found. Returning to menu... ") + print("Team " + str(delete_team) + " has not been found. ") continue elif user_action == "modify": - update_team = int(input("Which team would you like to modify? To return the to the menu, enter 0. \n ")) - if update_team == 0: - continue - elif update_team in teams.keys(): - update_variable = input("Which field would you like to modify: name, programming language, width, length, number of drivetrain motors, or camera vision? \n") - if update_variable not in teams[new_team].keys(): - print("There is no such field. Returning to menu... ") + update_team = input("Which team would you like to modify? To return the to the menu, enter 0. \n") + if update_team.isnumeric(): + update_team = int(update_team) + if update_team == 0: continue - change = input("Enter the new value. \n") - if update_variable in ["width", "length", "number of drivetrain motors"]: - if not change.isnumeric(): - print("Input is invalid. Returning to menu... ") + elif update_team in teams.keys(): + update_variable = input("Which field would you like to modify: name, programming language, width, length, number of drivetrain motors, or camera vision? \n") + if update_variable not in teams[new_team].keys(): + print("There is no such field. ") continue + change = input("Enter the new value. \n") + if update_variable in ["width", "length", "number of drivetrain motors"]: + if not change.isnumeric(): + print("Input is invalid. ") + continue + else: + teams[update_team][update_variable] = change + print("Successfully changed. ") + continue + elif update_variable == "camera vision": + if change != "True" and change != "False": + print("Please input True or False. ") + continue + else: + change = bool(change) + teams[update_team][update_variable] = change + print("Successfully changed. ") + continue else: teams[update_team][update_variable] = change - print("Successfully changed. Returning to menu... ") - continue - elif update_variable == "camera vision": - change = bool(change) - if not change == True or change == False: - print("Please input True or False. Returning to menu... ") + print("Successfully changed. ") continue - else: - teams[update_team][update_variable] = change - print("Successfully changed. Returning to menu... ") else: - teams[update_team][update_variable] = change - print("Successfully changed. Returning to menu... ") + print("Team " + str(update_team) + " was not found. ") continue else: - print("Team " + str(update_team) + " was not found. Returning to menu... ") + print("Team " + str(update_team) + " was not found. ") continue elif user_action == "add": new_team = input("Enter the number of the team you want to add. To return to the menu, enter 0. \n") if not new_team.isnumeric(): - print("Must be a number. Returning to menu... ") + print("Must be a number. ") continue elif new_team == "0": continue @@ -66,32 +72,32 @@ teams[new_team]["programming language"] = input("What programming language does the team use? \n") width = input("What is the width of the team's robot? \n") if not width.isnumeric(): - print("Width must be a number. Returning to menu... ") + print("Width must be a number. ") continue else: width = float(width) teams[new_team]["width"] = width length = input("What is the length of the team's robot? \n") if not length.isnumeric(): - print("Length must be a number. Returning to menu... ") + print("Length must be a number. ") continue else: length = float(width) teams[new_team]["length"] = length camera_vision = input("Does the team have a camera vision system? Input True or False. \n") - camera_vision = bool(camera_vision) - if not camera_vision == True or camera_vision == False: - print("Please follow directions. Returning to menu... ") + if camera_vision != "True" and camera_vision != "False": + print("Please follow directions.") continue else: + camera_vision = bool(camera_vision) teams[new_team]["camera vision"] = camera_vision drivetrain_motors = input("How many drivetrain motors does the robot have? \n") if not drivetrain_motors.isnumeric(): - print("Drivetrain motors must be a number. Returning to menu... ") + print("Drivetrain motors must be a number. ") continue else: teams[new_team]["number of drivetrain motors"] = drivetrain_motors - print("Team added. Returning to menu... ") + print("Team added. ") continue elif user_action == "view": @@ -108,16 +114,21 @@ print(teams[view_input]) continue else: - print("Team " + view_input + " has not been found. Returning to menu... ") + print("Team " + str(view_input) + " has not been found. ") continue elif user_action == "search": - search_input = int(input("Which team would you like to search for? To return to the menu, enter 0. \n")) - if search_input == 0: - continue - elif search_input in teams.keys(): - print(teams[search_input]) + search_input = input("Which team would you like to search for? To return to the menu, enter 0. \n") + if search_input.isnumeric(): + search_input = int(search_input) + if search_input == 0: + continue + elif search_input in teams.keys(): + print(teams[search_input]) + else: + print("Team does not exist. ") + continue else: - print("Team does not exist. Returning to menu... ") + print("Invalid team. ") continue elif user_action == "quit": break \ No newline at end of file From baea269fa095b2d27e87d47ddb7cf9319939e00b Mon Sep 17 00:00:00 2001 From: Kathy Date: Sat, 2 Nov 2019 20:08:26 -0700 Subject: [PATCH 16/20] add continuation --- ch_4_assign_kathy_li.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py index 3ba585f..80bc6d6 100644 --- a/ch_4_assign_kathy_li.py +++ b/ch_4_assign_kathy_li.py @@ -20,6 +20,8 @@ def distance(self): point_a = Point(x, y) print("The distance from the origin is " + str(point_a.distance())) +x = int(input("What is the x-value of your point? \n" )) +y = int(input("what is the y-value of your point? \n")) z = int(input("What is the z-value of your point? \n")) point_b = Point_3D(x, y, z) print("The distance from the origin is " + str(point_b.distance())) @@ -29,4 +31,4 @@ def distance(self): elif point_b.distance() > point_a.distance(): print("The 3D point is further from the origin than the 2D point.") elif point_a.distance() == point_b.distance(): - print("The points are the same length.") \ No newline at end of file + print("The points are the same distance from the origin.") \ No newline at end of file From d3c49ebaaa891fbc8b36c66d8c189f4ce9d95379 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 6 Nov 2019 19:45:55 -0800 Subject: [PATCH 17/20] Add validation --- ch_2_assign_kathy_li.py | 7 ++- ch_3_assign_kathy_li.py | 125 ++++++++++++++++++++++++---------------- ch_4_assign_kathy_li.py | 2 +- 3 files changed, 80 insertions(+), 54 deletions(-) diff --git a/ch_2_assign_kathy_li.py b/ch_2_assign_kathy_li.py index 22414ce..06d63db 100644 --- a/ch_2_assign_kathy_li.py +++ b/ch_2_assign_kathy_li.py @@ -26,7 +26,7 @@ continue elif update_team in teams.keys(): update_variable = input("Which field would you like to modify: name, programming language, width, length, number of drivetrain motors, or camera vision? \n") - if update_variable not in teams[new_team].keys(): + if update_variable not in teams[update_team].keys(): print("There is no such field. ") continue change = input("Enter the new value. \n") @@ -131,4 +131,7 @@ print("Invalid team. ") continue elif user_action == "quit": - break \ No newline at end of file + break + else: + print("Invalid action.") + continue \ No newline at end of file diff --git a/ch_3_assign_kathy_li.py b/ch_3_assign_kathy_li.py index 2227ceb..b295bfe 100644 --- a/ch_3_assign_kathy_li.py +++ b/ch_3_assign_kathy_li.py @@ -22,24 +22,34 @@ def list_teams(): print(teams) def remove_team(): - delete_team = int(input("Which team would you like to remove? \n")) - if delete_team in teams.keys(): - teams.pop(delete_team) - print("Team " + str(delete_team) + " has been removed. Returning to menu... ") - else: - print("Team " + str(delete_team) + " has not been found. Returning to menu... ") + if delete_team.isnumeric(): + if delete_team in teams.keys(): + teams.pop(delete_team) + print("Team " + str(delete_team) + " has been removed. ") + return + else: delete_team = input("Which team would you like to remove? \n") + print("Team " + str(delete_team) + " has not been found. ") + return + else: + print("Team must be a number.") + return + def search_team(): - search_input = int(input("Which team would you like to search for? \n")) - if search_input in teams.keys(): - print(teams[search_input]) + search_input = input("Which team would you like to search for? \n") + if search_input.isnumeric(): + if search_input in teams.keys(): + print(teams[search_input]) + else: + print("Team not found.") else: - print("Team does not exist. Returning to menu... ") + print("Team must be a number.") def add_team(): new_team = input("Enter the number of the team you want to add. \n") if new_team.isnumeric() == False: - print("Must be a number. Returning to menu... ") + print("Must be a number. ") + return else: new_team = int(new_team) teams[new_team] = {} @@ -49,65 +59,78 @@ def add_team(): rookie_year = input("What is the team's rookie year? \n") if not rookie_year.isnumeric(): - print("Rookie year must be a number. Returning to menu... ") + print("Rookie year must be a number. ") + return else: rookie_year = int(rookie_year) teams[new_team]["rookie year"] = rookie_year - - competed_in_2019 = input("Did they compete in 2019? Input True or False. \n") - competed_in_2019 = bool(competed_in_2019) - if not competed_in_2019 == True or competed_in_2019 == False: - print("Please follow directions. Returning to menu... ") - master_action() - elif competed_in_2019 == False: - print("Information added, returning to menu.") - else: - teams[new_team]["competed in 2019"] = competed_in_2019 - teams[new_team]["2019 competitions"] = input("What were their 2019 competitions? \n") - teams[new_team]["2019 awards"] = input("What awards did they receive in 2019? \n") - print("Team added. Returning to menu... ") + competed_in_2019 = input("Did they compete in 2019? Input True or False. \n") + if competed_in_2019 != "True" and competed_in_2019 != "False": + print("Please input True or False. ") + return + elif competed_in_2019 == "False": + competed_in_2019 = "" + competed_in_2019 = bool(competed_in_2019) + teams[new_team]["competed in 2019"] = competed_in_2019 + print("Team added.") + return + else: + competed_in_2019 = bool(competed_in_2019) + teams[new_team]["competed in 2019"] = competed_in_2019 + + teams[new_team]["2019 competitions"] = input("What were their 2019 competitions? \n") + teams[new_team]["2019 awards"] = input("What awards did they receive in 2019? \n") + print("Team added. ... ") + def view_team(): view_input = input("Which team's information would you like to view? \n") if not view_input.isnumeric(): - print("Team must be a number. Returning to menu... ") + print("Team must be a number. ") + return view_input = int(view_input) if view_input in teams: print(teams[view_input]) else: - print("Team " + view_input + " has not been found. Returning to menu... ") + print("Team " + str(view_input) + " has not been found. ") + return def modify_team(): - update_team = int(input("Which team would you like to modify? To return the to the menu, enter 0. \n ")) - if update_team in teams.keys(): - update_variable = input("Which field would you like to modify: name, location, rookie year, compteted in 2019, 2019 competitions, or 2019 awards? \n") - if update_variable not in teams[update_team].keys(): - print("There is no such field. Returning to menu... ") + update_team = input("Which team would you like to modify? To return the to the menu, enter 0. \n ") + if update_team.isnumeric(): + if update_team in teams.keys(): + update_variable = input("Which field would you like to modify: name, location, rookie year, compteted in 2019, 2019 competitions, or 2019 awards? \n") + if update_variable not in teams[update_team].keys(): + print("There is no such field. ") + return - change = input("Enter the new value. \n") - if update_variable == "rookie year": - if not change.isnumeric(): - print("Input is invalid. Returning to menu... ") - + change = input("Enter the new value. \n") + if update_variable == "rookie year": + if not change.isnumeric(): + print("Input is invalid. ") + return + else: + teams[update_team][update_variable] = change + print("Successfully changed. ") + + elif update_variable == "competed in 2019": + if change != "True" and change != "False": + print("Please input True or False. ") + return + else: + change = bool(change) + teams[update_team][update_variable] = change + print("Successfully changed. ") + return else: teams[update_team][update_variable] = change - print("Successfully changed. Returning to menu... ") - - elif update_variable == "competed in 2019": - change = bool(change) - if not change == True or change == False: - print("Please input True or False. Returning to menu... ") - - else: - teams[update_team][update_variable] = change - print("Successfully changed. Returning to menu... ") + print("Successfully changed. ") else: - teams[update_team][update_variable] = change - print("Successfully changed. Returning to menu... ") - + print("Team " + str(update_team) + " was not found. ") + return else: - print("Team " + str(update_team) + " was not found. Returning to menu... ") + print("Team must be a number.") def quit_program(): ##break diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py index 80bc6d6..5a1f60f 100644 --- a/ch_4_assign_kathy_li.py +++ b/ch_4_assign_kathy_li.py @@ -17,7 +17,7 @@ def distance(self): x = int(input("What is the x-value of your point? \n" )) y = int(input("what is the y-value of your point? \n")) -point_a = Point(x, y) +point_a = Point(x, y) print("The distance from the origin is " + str(point_a.distance())) x = int(input("What is the x-value of your point? \n" )) From d214793bf3f7235641d44993130e50a1de319bd7 Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 7 Nov 2019 18:23:41 -0800 Subject: [PATCH 18/20] skksks --- ch_3_assign_kathy_li.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch_3_assign_kathy_li.py b/ch_3_assign_kathy_li.py index b295bfe..75279e3 100644 --- a/ch_3_assign_kathy_li.py +++ b/ch_3_assign_kathy_li.py @@ -22,13 +22,13 @@ def list_teams(): print(teams) def remove_team(): + delete_team = input("Which team would you like to remove? \n") if delete_team.isnumeric(): if delete_team in teams.keys(): teams.pop(delete_team) print("Team " + str(delete_team) + " has been removed. ") return - else: delete_team = input("Which team would you like to remove? \n") - + else: print("Team " + str(delete_team) + " has not been found. ") return else: From e5c0ef192f3247e87b5c22cd136eb91992d2402c Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 13 Nov 2019 18:59:32 -0800 Subject: [PATCH 19/20] Change instance variables. Add validation. --- ch_4_assign_kathy_li.py | 78 +++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py index 5a1f60f..bafecc3 100644 --- a/ch_4_assign_kathy_li.py +++ b/ch_4_assign_kathy_li.py @@ -1,4 +1,5 @@ import math + class Point: def __init__ (self, x, y): self.x = x @@ -8,27 +9,60 @@ def distance(self): return math.sqrt(x**2 + y**2) class Point_3D(Point): - def __init__ (self, x, y, z): - super().__init__(x, y) - self.z = z + def __init__ (self, a, b, c): + self.a = a + self.b = b + self.c = c def distance(self): - return math.sqrt(x**2 + y**2 + z**2) - -x = int(input("What is the x-value of your point? \n" )) -y = int(input("what is the y-value of your point? \n")) -point_a = Point(x, y) -print("The distance from the origin is " + str(point_a.distance())) - -x = int(input("What is the x-value of your point? \n" )) -y = int(input("what is the y-value of your point? \n")) -z = int(input("What is the z-value of your point? \n")) -point_b = Point_3D(x, y, z) -print("The distance from the origin is " + str(point_b.distance())) - -if point_a.distance() > point_b.distance(): - print("The 2D point is further from the origin than the 3D point.") -elif point_b.distance() > point_a.distance(): - print("The 3D point is further from the origin than the 2D point.") -elif point_a.distance() == point_b.distance(): - print("The points are the same distance from the origin.") \ No newline at end of file + return math.sqrt(a**2 + b**2 + c**2) + +while True: + x = input("What is the x-value of your point? \n" ) + + if x.isnumeric(): + x = int(x) + else: + print("Invalid input.") + continue + + y = input("what is the y-value of your point? \n") + if y.isnumeric(): + y = int(y) + else: + print("Invalid input.") + continue + + point_a = Point(x, y) + print("The distance from the origin is " + str(point_a.distance())) + + a = input("What is the x-value of your point? \n" ) + if a.isnumeric(): + a = int(a) + else: + print("Invalid input.") + continue + + b = input("what is the y-value of your point? \n") + if b.isnumeric(): + b = int(b) + else: + print("Invalid input.") + continue + + c = input("What is the z-value of your point? \n") + if c.isnumeric(): + c = int(c) + else: + print("Invalid input.") + continue + point_b = Point_3D(a, b, c) + + print("The distance from the origin is " + str(point_b.distance())) + + if point_a.distance() > point_b.distance(): + print("The 2D point is further from the origin than the 3D point.") + elif point_b.distance() > point_a.distance(): + print("The 3D point is further from the origin than the 2D point.") + elif point_a.distance() == point_b.distance(): + print("The points are the same distance from the origin.") \ No newline at end of file From 899e716d8c9aa622d445a010f37227d4293203f6 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 13 Nov 2019 19:15:54 -0800 Subject: [PATCH 20/20] Change 3D point variables to "x", "y", and "z". Add super() function. --- ch_4_assign_kathy_li.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ch_4_assign_kathy_li.py b/ch_4_assign_kathy_li.py index bafecc3..aea0a2f 100644 --- a/ch_4_assign_kathy_li.py +++ b/ch_4_assign_kathy_li.py @@ -6,16 +6,15 @@ def __init__ (self, x, y): self.y = y def distance(self): - return math.sqrt(x**2 + y**2) + return math.sqrt(self.x**2 + self.y**2) class Point_3D(Point): - def __init__ (self, a, b, c): - self.a = a - self.b = b - self.c = c + def __init__ (self, x, y, z): + super().__init__(x, y) + self.z = z def distance(self): - return math.sqrt(a**2 + b**2 + c**2) + return math.sqrt(self.x**2 + self.y**2 + self.z**2) while True: x = input("What is the x-value of your point? \n" ) @@ -36,27 +35,27 @@ def distance(self): point_a = Point(x, y) print("The distance from the origin is " + str(point_a.distance())) - a = input("What is the x-value of your point? \n" ) - if a.isnumeric(): - a = int(a) + x = input("What is the x-value of your point? \n" ) + if x.isnumeric(): + x = int(x) else: print("Invalid input.") continue - b = input("what is the y-value of your point? \n") - if b.isnumeric(): - b = int(b) + y = input("what is the y-value of your point? \n") + if y.isnumeric(): + y = int(y) else: print("Invalid input.") continue - c = input("What is the z-value of your point? \n") - if c.isnumeric(): - c = int(c) + z = input("What is the z-value of your point? \n") + if z.isnumeric(): + z = int(z) else: print("Invalid input.") continue - point_b = Point_3D(a, b, c) + point_b = Point_3D(x, y, z) print("The distance from the origin is " + str(point_b.distance())) @@ -65,4 +64,5 @@ def distance(self): elif point_b.distance() > point_a.distance(): print("The 3D point is further from the origin than the 2D point.") elif point_a.distance() == point_b.distance(): - print("The points are the same distance from the origin.") \ No newline at end of file + print("The points are the same distance from the origin.") + break \ No newline at end of file