From a9f513f3bf2a0b4d70d9a34050f2d1532b159d45 Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Wed, 11 Sep 2019 19:34:21 -0700 Subject: [PATCH 01/11] add hello world --- ch_1_lesson_kelly_su.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 ch_1_lesson_kelly_su.py diff --git a/ch_1_lesson_kelly_su.py b/ch_1_lesson_kelly_su.py new file mode 100644 index 0000000..91c2faf --- /dev/null +++ b/ch_1_lesson_kelly_su.py @@ -0,0 +1 @@ +print ('Hello, world!') \ No newline at end of file From c36920cd08901dd4e4a67180ca9db3df593decbd Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Thu, 12 Sep 2019 20:46:41 -0700 Subject: [PATCH 02/11] added teams dictionary --- ch_1_assign_kelly_su.py | 45 +++++++++++++++++++++++++++++++ ch_1_robot_assignment_kelly_su.py | 6 +++++ 2 files changed, 51 insertions(+) create mode 100644 ch_1_assign_kelly_su.py create mode 100644 ch_1_robot_assignment_kelly_su.py diff --git a/ch_1_assign_kelly_su.py b/ch_1_assign_kelly_su.py new file mode 100644 index 0000000..46569d7 --- /dev/null +++ b/ch_1_assign_kelly_su.py @@ -0,0 +1,45 @@ +teams = { + 1: {"location": "Pontiac, Michigan, USA", + "rookie year": 1997, + "competed in 2019 season": True, + "2019 competitions and locations": {"FIM District Center Line Event", "Center Line, MI, USA". + "FIM District Troy Event", "Troy, MI, USA". + } + "2019 season awards": {"Imagery Award"} + } + 16: {"location": "Mountain Home, Arkansas, USA", + "rookie year": 1996, + "competed in 2019 season": True, + "2019 competitions and locations": {"Midwest Regional", "Chicago, IL, USA". + "Rocket City Regional", "Huntsville, AL, USA". + "Darwin Division", "Detroit, MI, USA". + } + "2019 season awards": {"Industrial Design Award", "Regional Finalists", "Excellence in Engineering Award"} + } + 253: {"location": "Millbrae, California, USA", + "rookie year": 1999, + "competed in 2019 season": True, + "2019 competitions and locations": {"San Fransisco Regional", "San Fransisco, California, USA". + "Monterey Bay Regional", "Seaside, CA, USA". + "Newton Division", "Houston, TX, USA". + } + "2019 season awards": {"Team Spirit Award"} + } + 342: {"location": "North Charleston, South Carolina, USA", + "rookie year": 2000, + "competed in 2019 season": True, + "2019 competitions and locations": {"Palmetto Regional", "Myrtle Beach, SC USA". + "Rocket City Regional", "Huntsville, AL, USA". + } + "2019 season awards": False + } + 554: {"location": "Ft. Thomas, Kentucky, USA", + "rookie year": 2001, + "competed in 2019 season": True, + "2019 competitions and locations": {"Miami Valley Regional", "Dayton, OH, USA". + } + "2019 season awards": False + } +requested_team_number = input("Team Number: ") +requested_team_information = input(requested_team_number + "information: ") +print([teams][requested_team_number][requested_team_information]) \ No newline at end of file diff --git a/ch_1_robot_assignment_kelly_su.py b/ch_1_robot_assignment_kelly_su.py new file mode 100644 index 0000000..bb929ba --- /dev/null +++ b/ch_1_robot_assignment_kelly_su.py @@ -0,0 +1,6 @@ +teams = { + 1678: {"weight": 150, "color": "purple", "wheels": 4} + 2874: {"weight": 110, "color": "green", "wheels": 6} + 259: {"weight": 248, "color": "blue", "wheels": 2} +} +requested_team_number = input("Team Number: ") \ No newline at end of file From 9b39fae75caa9614d519f8be07e40ea2e7be4ebf Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Thu, 26 Sep 2019 19:41:23 -0700 Subject: [PATCH 03/11] Fix input syntax --- ch_1_assign_kelly_su.py | 96 ++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/ch_1_assign_kelly_su.py b/ch_1_assign_kelly_su.py index 46569d7..94ce0ff 100644 --- a/ch_1_assign_kelly_su.py +++ b/ch_1_assign_kelly_su.py @@ -1,45 +1,53 @@ teams = { - 1: {"location": "Pontiac, Michigan, USA", - "rookie year": 1997, - "competed in 2019 season": True, - "2019 competitions and locations": {"FIM District Center Line Event", "Center Line, MI, USA". - "FIM District Troy Event", "Troy, MI, USA". - } - "2019 season awards": {"Imagery Award"} - } - 16: {"location": "Mountain Home, Arkansas, USA", - "rookie year": 1996, - "competed in 2019 season": True, - "2019 competitions and locations": {"Midwest Regional", "Chicago, IL, USA". - "Rocket City Regional", "Huntsville, AL, USA". - "Darwin Division", "Detroit, MI, USA". - } - "2019 season awards": {"Industrial Design Award", "Regional Finalists", "Excellence in Engineering Award"} - } - 253: {"location": "Millbrae, California, USA", - "rookie year": 1999, - "competed in 2019 season": True, - "2019 competitions and locations": {"San Fransisco Regional", "San Fransisco, California, USA". - "Monterey Bay Regional", "Seaside, CA, USA". - "Newton Division", "Houston, TX, USA". - } - "2019 season awards": {"Team Spirit Award"} - } - 342: {"location": "North Charleston, South Carolina, USA", - "rookie year": 2000, - "competed in 2019 season": True, - "2019 competitions and locations": {"Palmetto Regional", "Myrtle Beach, SC USA". - "Rocket City Regional", "Huntsville, AL, USA". - } - "2019 season awards": False - } - 554: {"location": "Ft. Thomas, Kentucky, USA", - "rookie year": 2001, - "competed in 2019 season": True, - "2019 competitions and locations": {"Miami Valley Regional", "Dayton, OH, USA". - } - "2019 season awards": False - } -requested_team_number = input("Team Number: ") -requested_team_information = input(requested_team_number + "information: ") -print([teams][requested_team_number][requested_team_information]) \ No newline at end of file + 1: {'location': 'Pontiac, Michigan, USA', + 'rookie year': 1997, + 'competed in 2019 season': True, + '2019 competitions': 'FIM District Center Line Event: Center Line, MI, USA; ' + 'FIM District Troy Event: Troy, MI, USA', + '2019 season awards':'Imagery Award' + }, + 16: {'location': 'Mountain Home, Arkansas, USA', + 'rookie year': 1996, + 'competed in 2019 season': True, + '2019 competitions': 'Midwest Regional: Chicago, IL, USA' + 'Rocket City Regional: Huntsville, AL, USA; ' + 'Darwin Division: Detroit, MI, USA', + '2019 season awards': 'Industrial Design Award, Regional Finalists, Excellence in Engineering Award' + }, + 253: {'location': 'Millbrae, California, USA', + 'rookie year': 1999, + 'competed in 2019 season': True, + '2019 competitions': 'San Fransisco Regional: San Fransisco, California, USA; ' + 'Monterey Bay Regional: Seaside, CA, USA; ' + 'Newton Division: Houston, TX, USA', + '2019 season awards': 'Team Spirit Award' + }, + 342: {'location': 'North Charleston, South Carolina, USA', + 'rookieyear': 2000, + 'competed in 2019 season': True, + '2019 competitions': 'Palmetto Regional: Myrtle Beach, SC USA;' + 'Rocket City Regional: Huntsville, AL, USA', + '2019 season awards': False + }, + 554: {'location': 'Ft. Thomas, Kentucky, USA', + 'rookie year': 2001, + 'competed in 2019 season': True, + '2019 competitions': 'Miami Valley Regional: Dayton, OH, USA', + '2019 season awards': False + }, +} + +input_team = int(input("Out of teams 1, 16, 253, 342, and 554, which one would you like to view?\n==>")) +input_requested_information = str(input( +"""What would you like to know about this team? + Please enter one of the following: + location + rookie year + competed in 2019 season + 2019 competitions + 2019 season awards\n==>""")) +print(teams[input_team][input_requested_information]) + + + + From 9177980879d7d7d259ba815696cfe81753e72381 Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Thu, 26 Sep 2019 20:14:57 -0700 Subject: [PATCH 04/11] add lists to 2019 competitions --- ch_1_assign_kelly_su.py | 63 +++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/ch_1_assign_kelly_su.py b/ch_1_assign_kelly_su.py index 94ce0ff..14b1bcd 100644 --- a/ch_1_assign_kelly_su.py +++ b/ch_1_assign_kelly_su.py @@ -1,52 +1,59 @@ teams = { - 1: {'location': 'Pontiac, Michigan, USA', + 1: { + 'location': 'Pontiac, Michigan, USA.', 'rookie year': 1997, 'competed in 2019 season': True, - '2019 competitions': 'FIM District Center Line Event: Center Line, MI, USA; ' - 'FIM District Troy Event: Troy, MI, USA', + '2019 competitions': ['FIM District Center Line Event: Center Line, MI, USA.', + 'FIM District Troy Event: Troy, MI, USA.'], '2019 season awards':'Imagery Award' - }, - 16: {'location': 'Mountain Home, Arkansas, USA', + }, + 16: { + 'location': 'Mountain Home, Arkansas, USA.', 'rookie year': 1996, 'competed in 2019 season': True, - '2019 competitions': 'Midwest Regional: Chicago, IL, USA' - 'Rocket City Regional: Huntsville, AL, USA; ' - 'Darwin Division: Detroit, MI, USA', + '2019 competitions': ['Midwest Regional: Chicago, IL, USA.', + 'Rocket City Regional: Huntsville, AL, USA.', + 'Darwin Division: Detroit, MI, USA.'], '2019 season awards': 'Industrial Design Award, Regional Finalists, Excellence in Engineering Award' - }, - 253: {'location': 'Millbrae, California, USA', - 'rookie year': 1999, - 'competed in 2019 season': True, - '2019 competitions': 'San Fransisco Regional: San Fransisco, California, USA; ' - 'Monterey Bay Regional: Seaside, CA, USA; ' - 'Newton Division: Houston, TX, USA', - '2019 season awards': 'Team Spirit Award' - }, - 342: {'location': 'North Charleston, South Carolina, USA', + }, + 253: { + 'location': 'Millbrae, California, USA.', + 'rookie year': 1999, + 'competed in 2019 season': True, + '2019 competitions': ['San Fransisco Regional: San Fransisco, California, USA.', + 'Monterey Bay Regional: Seaside, CA, USA.', + 'Newton Division: Houston, TX, USA.'], + '2019 season awards': 'Team Spirit Award' + }, + 342: {'location': 'North Charleston, South Carolina, USA.', 'rookieyear': 2000, 'competed in 2019 season': True, - '2019 competitions': 'Palmetto Regional: Myrtle Beach, SC USA;' - 'Rocket City Regional: Huntsville, AL, USA', + '2019 competitions': ['Palmetto Regional: Myrtle Beach, SC USA.', + 'Rocket City Regional: Huntsville, AL, USA.'], '2019 season awards': False }, - 554: {'location': 'Ft. Thomas, Kentucky, USA', - 'rookie year': 2001, - 'competed in 2019 season': True, - '2019 competitions': 'Miami Valley Regional: Dayton, OH, USA', - '2019 season awards': False + 554: { + 'location': 'Ft. Thomas, Kentucky, USA.', + 'rookie year': 2001, + 'competed in 2019 season': True, + '2019 competitions': ['Miami Valley Regional: Dayton, OH, USA.'], + '2019 season awards': False }, } input_team = int(input("Out of teams 1, 16, 253, 342, and 554, which one would you like to view?\n==>")) -input_requested_information = str(input( +input_requested_information = input( """What would you like to know about this team? Please enter one of the following: location rookie year competed in 2019 season 2019 competitions - 2019 season awards\n==>""")) -print(teams[input_team][input_requested_information]) + 2019 season awards\n==>""") +if isinstance(teams[input_team][input_requested_information], list): + print("\n".join(teams[input_team][input_requested_information])) +else: + print(teams[input_team][input_requested_information]) From 962f3629e622c7762da187d9da05636502cb6610 Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Thu, 26 Sep 2019 20:27:22 -0700 Subject: [PATCH 05/11] finish code --- ch_2_assign_kelly_su.py | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 ch_2_assign_kelly_su.py diff --git a/ch_2_assign_kelly_su.py b/ch_2_assign_kelly_su.py new file mode 100644 index 0000000..bf78b32 --- /dev/null +++ b/ch_2_assign_kelly_su.py @@ -0,0 +1,83 @@ +all_team_dict = {} +def add_team(): + input_num = input("Please enter a team number to add/update or 0 to exit.\n(If the team already exists, the information will be updated.)\n==>") + if input_num == '0': + return + input_name = input("Please enter the team name.\n==>") + input_prog_lang = input("Please enter the programming language.\n==>") + input_w = input("Please enter the width.\n==>") + input_l = input ("Please enter the length.\n==>") + input_cam_vision = input("Does it have a camera vision system? Please answer 'yes' or 'no'.\n==>") + input_motors = input("Please enter the number of drivetrain motors.\n==>") + + team_dict = {} + team_dict ["number"] = input_num + team_dict ["name"] = input_name + team_dict ["prog_lang"] = input_prog_lang + team_dict ["w"] = input_w + team_dict ["l"] = input_l + team_dict ["cam_vision"] = input_cam_vision + team_dict ["motors"] = input_motors + + all_team_dict.update( {input_num : team_dict} ) + print("Successfully added team " + input_num + "!") + +def view_team(): + input_viewteam = input("Please enter a team number to view or 0 to exit.\n==>") + if input_viewteam == '0': + return + elif input_viewteam in all_team_dict.keys(): + team_dict = all_team_dict.get(input_viewteam) + print(" Number = " + team_dict ["number"] + '\n' + + " Name = " + team_dict ["name"] + '\n' + + " Programming Language = " + team_dict ["prog_lang"] + '\n' + + " Width = " + team_dict ["w"] + '\n' + + " Length = " + team_dict ["l"] + '\n' + + " Camera Vision System = " + team_dict ["cam_vision"] + '\n' + + " Number of drivetrain motors = " + team_dict ["motors"] + '\n' + ) + else: + print("Team " + input_viewteam + " not found!") + +def remove_team(): + input_viewteam = input("Please enter a team number to delete or 0 to exit. \n==>") + if input_viewteam == '0': + return + elif input_viewteam in all_team_dict.keys(): + all_team_dict.pop(input_viewteam) + print("Team " + input_viewteam + " removed!") + else: + print("Team " + input_viewteam + " not found!") + + +def list_teams(): + big_list = all_team_dict.values() + for team_dict in big_list: + print(" Number = " + team_dict ["number"] + '\n' + + " Name = " + team_dict ["name"] + '\n' + + " Programming Language = " + team_dict ["prog_lang"] + '\n' + + " Width = " + team_dict ["w"] + '\n' + + " Length = " + team_dict ["l"] + '\n' + + " Camera Vision System = " + team_dict ["cam_vision"] + '\n' + + " Number of drivetrain motors = " + team_dict ["motors"] + '\n' + + "------------------------------------------------" + ) + return + +while True: + print("MAIN MENU:") + selection = input("Press \n 1 to add/update a team,\n 2 to view a team,\n 3 to remove a team,\n 4 to list all teams.\n==>") + if selection == '1': + add_team() + elif selection == '2': + view_team() + elif selection == '3': + remove_team() + elif selection == '4': + list_teams() + else: + print("I'm sorry, I did not understand that.") + + + + From b3b2fcca24bd706b92c068350aa73da32b31c10a Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Sun, 29 Sep 2019 22:13:23 -0700 Subject: [PATCH 06/11] add validation to inputs --- ch_2_assign_kelly_su.py | 56 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/ch_2_assign_kelly_su.py b/ch_2_assign_kelly_su.py index bf78b32..f16b46d 100644 --- a/ch_2_assign_kelly_su.py +++ b/ch_2_assign_kelly_su.py @@ -1,23 +1,59 @@ all_team_dict = {} +team_dict = {} def add_team(): input_num = input("Please enter a team number to add/update or 0 to exit.\n(If the team already exists, the information will be updated.)\n==>") if input_num == '0': + print("Exiting...") return + elif (input_num.isdigit()): + team_dict["number"] = input_num + else: + print("Invalid input.") + return + input_name = input("Please enter the team name.\n==>") + if isinstance(input_name, str): + team_dict["name"] = input_name + else: + print("Invalid input.") + return + input_prog_lang = input("Please enter the programming language.\n==>") + if isinstance(input_name, str): + team_dict["prog_lang"] = input_prog_lang + else: + print("Invalid input.") + return + input_w = input("Please enter the width.\n==>") + if (input_w.isdigit()): + team_dict["w"] = input_w + else: + print("Invalid input.") + return + input_l = input ("Please enter the length.\n==>") - input_cam_vision = input("Does it have a camera vision system? Please answer 'yes' or 'no'.\n==>") - input_motors = input("Please enter the number of drivetrain motors.\n==>") + if (input_l.isdigit()): + team_dict["l"] = input_l + else: + print("Invalid input.") + return - team_dict = {} - team_dict ["number"] = input_num - team_dict ["name"] = input_name - team_dict ["prog_lang"] = input_prog_lang - team_dict ["w"] = input_w - team_dict ["l"] = input_l - team_dict ["cam_vision"] = input_cam_vision - team_dict ["motors"] = input_motors + input_cam_vision = input("Does it have a camera vision system? Please answer 'true' or 'false'.\n==>") + if input_cam_vision == 'true': + team_dict["cam_vision"] = input_cam_vision + elif input_cam_vision == 'false': + team_dict["cam_vision"] = input_cam_vision + else: + print("Invalid input.") + return + + input_motors = input("Please enter the number of drivetrain motors.\n==>") + if (input_motors.isdigit()): + team_dict["motors"] = input_motors + else: + print("Invalid input.") + return all_team_dict.update( {input_num : team_dict} ) print("Successfully added team " + input_num + "!") From cdfea179adbf1d8282e93c4888f2a7f9076df74d Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Thu, 3 Oct 2019 19:10:57 -0700 Subject: [PATCH 07/11] prompt will repeat when input is invalid --- ch_2_assign_kelly_su.py | 98 +++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/ch_2_assign_kelly_su.py b/ch_2_assign_kelly_su.py index f16b46d..57e05c5 100644 --- a/ch_2_assign_kelly_su.py +++ b/ch_2_assign_kelly_su.py @@ -1,22 +1,24 @@ all_team_dict = {} team_dict = {} def add_team(): - input_num = input("Please enter a team number to add/update or 0 to exit.\n(If the team already exists, the information will be updated.)\n==>") - if input_num == '0': - print("Exiting...") - return - elif (input_num.isdigit()): - team_dict["number"] = input_num - else: - print("Invalid input.") - return + while True: + input_num = input("Please enter a team number to add/update or 0 to exit.\n(If the team already exists, the information will be updated.)\n==>") + if input_num == '0': + print("Exiting...") + return + elif (input_num.isdigit()): + team_dict["number"] = input_num + break + else: + print("Invalid input.") - input_name = input("Please enter the team name.\n==>") - if isinstance(input_name, str): - team_dict["name"] = input_name - else: - print("Invalid input.") - return + while True: + input_name = input("Please enter the team name.\n==>") + if (input_name.isdigit()): + print("Invalid input.") + else: + team_dict["name"] = input_name + break input_prog_lang = input("Please enter the programming language.\n==>") if isinstance(input_name, str): @@ -25,42 +27,48 @@ def add_team(): print("Invalid input.") return - input_w = input("Please enter the width.\n==>") - if (input_w.isdigit()): - team_dict["w"] = input_w - else: - print("Invalid input.") - return - - input_l = input ("Please enter the length.\n==>") - if (input_l.isdigit()): - team_dict["l"] = input_l - else: - print("Invalid input.") - return + while True: + input_w = input("Please enter the width.\n==>") + if (input_w.isdigit()): + team_dict["w"] = input_w + break + else: + print("Invalid input.") - input_cam_vision = input("Does it have a camera vision system? Please answer 'true' or 'false'.\n==>") - if input_cam_vision == 'true': - team_dict["cam_vision"] = input_cam_vision - elif input_cam_vision == 'false': - team_dict["cam_vision"] = input_cam_vision - else: - print("Invalid input.") - return + while True: + input_l = input ("Please enter the length.\n==>") + if (input_l.isdigit()): + team_dict["l"] = input_l + break + else: + print("Invalid input.") - input_motors = input("Please enter the number of drivetrain motors.\n==>") - if (input_motors.isdigit()): - team_dict["motors"] = input_motors - else: - print("Invalid input.") - return + while True: + input_cam_vision = input("Does it have a camera vision system? Please answer 'true' or 'false'.\n==>") + if input_cam_vision == 'true': + team_dict["cam_vision"] = input_cam_vision + break + elif input_cam_vision == 'false': + team_dict["cam_vision"] = input_cam_vision + break + else: + print("Invalid input.") + while True: + input_motors = input("Please enter the number of drivetrain motors.\n==>") + if (input_motors.isdigit()): + team_dict["motors"] = input_motors + break + else: + print("Invalid input.") + all_team_dict.update( {input_num : team_dict} ) print("Successfully added team " + input_num + "!") def view_team(): input_viewteam = input("Please enter a team number to view or 0 to exit.\n==>") if input_viewteam == '0': + print("Exiting...") return elif input_viewteam in all_team_dict.keys(): team_dict = all_team_dict.get(input_viewteam) @@ -78,6 +86,7 @@ def view_team(): def remove_team(): input_viewteam = input("Please enter a team number to delete or 0 to exit. \n==>") if input_viewteam == '0': + print("Exiting...") return elif input_viewteam in all_team_dict.keys(): all_team_dict.pop(input_viewteam) @@ -98,7 +107,10 @@ def list_teams(): " Number of drivetrain motors = " + team_dict ["motors"] + '\n' + "------------------------------------------------" ) - return + return + else: + print("No teams found!") + return while True: print("MAIN MENU:") From df2513f59fc7a8543162a66c412444e2d59a7149 Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Sun, 13 Oct 2019 20:14:17 -0700 Subject: [PATCH 08/11] finish code --- ch_3_assign_kelly_su.py | 124 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 ch_3_assign_kelly_su.py diff --git a/ch_3_assign_kelly_su.py b/ch_3_assign_kelly_su.py new file mode 100644 index 0000000..705272f --- /dev/null +++ b/ch_3_assign_kelly_su.py @@ -0,0 +1,124 @@ +all_team_dict = {} +team_dict = {} +def add_team(): + while True: + input_num = input("Please enter a team number to add/update or 0 to exit.\n(If the team already exists, the information will be updated.)\n==>") + if input_num == '0': + print("Exiting...") + return + elif (input_num.isdigit()): + team_dict["number"] = input_num + break + else: + print("Invalid input.") + + while True: + input_name = input("Please enter the team name.\n==>") + if (input_name.isdigit()): + print("Invalid input.") + else: + team_dict["name"] = input_name + break + + while True: + input_location = input("Please enter the location of the team.\n==>") + if (input_location.isdigit()): + print("Invalid input.") + else: + team_dict["location"] = input_location + break + + while True: + input_rookie_year = input("Please enter the rookie year of the team.\n==>") + if (input_rookie_year.isdigit()): + team_dict["rookie year"] = input_rookie_year + break + else: + print("Invalid input.") + + while True: + input_2019_season = input("Did this team compete in the 2019 season? Please answer 'true' or 'false'.\n==>") + if input_2019_season == 'true': + input_2019_season = input("Which 2019 competitions did this team compete in? \n==>") + team_dict["2019 competitions"] = input_2019_season + break + elif input_2019_season == 'false': + team_dict["2019 competitions"] = input_2019_season + break + else: + print("Invalid input.") + + while True: + input_2019_awards = input("Did this team win any awards in the 2019 season? Please answer 'true or 'false' \n==>") + if input_2019_awards == 'true': + input_awards_won = input("Which awards did this team win? \n==>") + team_dict["2019 awards"] = input_awards_won + break + elif input_2019_awards == 'false': + team_dict["2019 awards"] = input_2019_awards + break + else: + print("Invalid input.") + + all_team_dict.update( {input_num : team_dict} ) + print("Successfully added team " + input_num + "!") + +def view_team(): + input_viewteam = input("Please enter a team number to view or 0 to exit.\n==>") + if input_viewteam == '0': + print("Exiting...") + return + elif input_viewteam in all_team_dict.keys(): + team_dict = all_team_dict.get(input_viewteam) + print(" Number = " + team_dict["number"] + '\n' + + " Name = " + team_dict["name"] + '\n' + + " Location = " + team_dict["location"] + '\n' + + " Rookie Year = " + team_dict["rookie year"] + '\n' + + " 2019 competitions = " + team_dict["2019 competitions"] + '\n' + " 2019 awards = " + team_dict["2019 awards"] + '\n' + ) + else: + print("Team " + input_viewteam + " not found!") + +def remove_team(): + input_viewteam = input("Please enter a team number to delete or 0 to exit. \n==>") + if input_viewteam == '0': + print("Exiting...") + return + elif input_viewteam in all_team_dict.keys(): + all_team_dict.pop(input_viewteam) + print("Team " + input_viewteam + " removed!") + else: + print("Team " + input_viewteam + " not found!") + + +def list_teams(): + big_list = all_team_dict.values() + for team_dict in big_list: + print(" Number = " + team_dict["number"] + '\n' + + " Name = " + team_dict["name"] + '\n' + + " Location = " + team_dict["location"] + '\n' + + " Rookie Year = " + team_dict["rookie year"] + '\n' + + " 2019 competitions = " + team_dict["2019 competitions"] + '\n' + " 2019 awards = " + team_dict["2019 awards"] + '\n' + + "--------------------------------------------------" + ) + else: + print("No teams found!") + return + +while True: + print("MAIN MENU:") + selection = input("Press \n 1 to add/update a team,\n 2 to view a team,\n 3 to remove a team,\n 4 to list all teams.\n==>") + if selection == '1': + add_team() + elif selection == '2': + view_team() + elif selection == '3': + remove_team() + elif selection == '4': + list_teams() + else: + print("I'm sorry, I did not understand that.") + + + + From 6c78c98590bbf4b79aed148077c10c41115fc660 Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Wed, 23 Oct 2019 20:22:44 -0700 Subject: [PATCH 09/11] finish code --- ch_4_assign_kelly_su.py | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 ch_4_assign_kelly_su.py diff --git a/ch_4_assign_kelly_su.py b/ch_4_assign_kelly_su.py new file mode 100644 index 0000000..27662c1 --- /dev/null +++ b/ch_4_assign_kelly_su.py @@ -0,0 +1,76 @@ +from math import sqrt; +import math; +class Point: + def __init__(self, x, y): + self.x = x + self.y = y + def distance_2D (self): + return float(sqrt(math.pow(int(self.x), 2) + math.pow(int(self.y),2))) + +while True: + x = input("Please enter your 2D x value.\n==>") + if (x.isdigit()): + break + else: + print("Invalid input.") + +while True: + y = input("Please enter your 2D y value.\n==>") + if (y.isdigit()): + break + else: + print("Invalid input.") + + +point_one = Point(x, y) +print("The distance is " + str(point_one.distance_2D()) + "\n") + +class Point_3D(Point): + def __init__(self, x, y, z): + super().__init__(x, y) + self.z = z + def distance_3D(self): + return float(sqrt(math.pow(int(self.x), 2) + math.pow(int(self.y), 2) + math.pow(int(self.z), 2))) + def distance_2D(self): + return super().distance_2D() + +while True: + x = input("Please enter your 3D x value.\n==>") + if (x.isdigit()): + break + else: + print("Invalid input.") + +while True: + y = input("Please enter your 3D y value.\n==>") + if (y.isdigit()): + break + else: + print("Invalid input.") + +while True: + z = input("Please enter your 3D z value.\n==>") + if (z.isdigit()): + break + else: + print("Invalid input.") + +point_two = Point_3D(x, y, z) +print("The distance is " + str(point_two.distance_3D()) + "\n") + +if (point_one.distance_2D()) > (point_two.distance_3D()): + print("The 2D point is furthest from the origin.") +elif (point_one.distance_2D()) < (point_two.distance_3D()): + print("The 3D point is furthest from the origin.") +elif (point_one.distance_2D()) == (point_two.distance_3D()): + print("The 2D and 3D point have equally furthest from the origin.") + +if (point_one.distance_2D()) > (point_two.distance_2D()): + print("The 2D point has x and y coordinates furthest from the origin.") +elif (point_one.distance_2D()) < (point_two.distance_2D()): + print("The 3D point has x and y coordinates furthest from the origin.") +elif (point_one.distance_2D()) == (point_two.distance_2D()): + print("The 2D and 3D x and y coordinates have equal values.") + + + From 9b407d2df5cf238108348f40acc61147cbb0de03 Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Wed, 30 Oct 2019 19:46:53 -0700 Subject: [PATCH 10/11] add search function --- ch_2_assign_kelly_su.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/ch_2_assign_kelly_su.py b/ch_2_assign_kelly_su.py index 57e05c5..539399e 100644 --- a/ch_2_assign_kelly_su.py +++ b/ch_2_assign_kelly_su.py @@ -65,11 +65,24 @@ def add_team(): all_team_dict.update( {input_num : team_dict} ) print("Successfully added team " + input_num + "!") +def search_team(): + input_searchteam = input("Please enter a team number to check if it exists or 0 to exit.\n==>") + if input_searchteam == '0': + print("Exiting...") + return + elif input_searchteam in all_team_dict.keys(): + print("Yes, team " + input_searchteam + " does exist.") + elif input_searchteam == team_dict["name"]: + print("Yes, team " + input_searchteam + " does exist.") + else: + print("Team " + input_searchteam + " does not exist!") + def view_team(): input_viewteam = input("Please enter a team number to view or 0 to exit.\n==>") if input_viewteam == '0': print("Exiting...") return + elif input_viewteam in all_team_dict.keys(): team_dict = all_team_dict.get(input_viewteam) print(" Number = " + team_dict ["number"] + '\n' + @@ -80,19 +93,20 @@ def view_team(): " Camera Vision System = " + team_dict ["cam_vision"] + '\n' + " Number of drivetrain motors = " + team_dict ["motors"] + '\n' ) + else: print("Team " + input_viewteam + " not found!") def remove_team(): - input_viewteam = input("Please enter a team number to delete or 0 to exit. \n==>") - if input_viewteam == '0': + input_removeteam = input("Please enter a team number to delete or 0 to exit. \n==>") + if input_removeteam == '0': print("Exiting...") return - elif input_viewteam in all_team_dict.keys(): - all_team_dict.pop(input_viewteam) - print("Team " + input_viewteam + " removed!") + elif input_removeteam in all_team_dict.keys(): + all_team_dict.pop(input_removeteam) + print("Team " + input_removeteam + " removed!") else: - print("Team " + input_viewteam + " not found!") + print("Team " + input_removeteam + " not found!") def list_teams(): @@ -114,14 +128,16 @@ def list_teams(): while True: print("MAIN MENU:") - selection = input("Press \n 1 to add/update a team,\n 2 to view a team,\n 3 to remove a team,\n 4 to list all teams.\n==>") + selection = input("Press \n 1 to add/update a team,\n 2 to search for a team,\n 3 to view a team's information,\n 4 to remove a team,\n 5 to list all teams.\n==>") if selection == '1': add_team() - elif selection == '2': + elif selection == '2': + search_team() + elif selection == '3': view_team() - elif selection == '3': - remove_team() elif selection == '4': + remove_team() + elif selection == '5': list_teams() else: print("I'm sorry, I did not understand that.") From 95bfaf17628f6e11f687ef9862247a0fb8a81b1e Mon Sep 17 00:00:00 2001 From: Kelly Su Date: Mon, 11 Nov 2019 22:10:00 -0800 Subject: [PATCH 11/11] fix search function search function now works when no teams are scored --- ch_1_robot_assignment_kelly_su.py | 3 ++- ch_2_assign_kelly_su.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ch_1_robot_assignment_kelly_su.py b/ch_1_robot_assignment_kelly_su.py index bb929ba..5ac6b79 100644 --- a/ch_1_robot_assignment_kelly_su.py +++ b/ch_1_robot_assignment_kelly_su.py @@ -3,4 +3,5 @@ 2874: {"weight": 110, "color": "green", "wheels": 6} 259: {"weight": 248, "color": "blue", "wheels": 2} } -requested_team_number = input("Team Number: ") \ No newline at end of file +requested_team_number = input("Team Number: ") +requested_robot_attribute = input("Robot Attribute: ") diff --git a/ch_2_assign_kelly_su.py b/ch_2_assign_kelly_su.py index 539399e..71694d4 100644 --- a/ch_2_assign_kelly_su.py +++ b/ch_2_assign_kelly_su.py @@ -66,6 +66,9 @@ def add_team(): print("Successfully added team " + input_num + "!") def search_team(): + if len(team_dict) == 0: + print("No teams found.") + return input_searchteam = input("Please enter a team number to check if it exists or 0 to exit.\n==>") if input_searchteam == '0': print("Exiting...")