From 207069854a23e2853eea6642f3a690be29a9f1be Mon Sep 17 00:00:00 2001 From: Emily Xia Date: Wed, 11 Sep 2019 19:51:26 -0700 Subject: [PATCH 01/25] add ch_1_lesson_emily_xia.py to repository --- ch_1_lesson_emily_xia.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 ch_1_lesson_emily_xia.py diff --git a/ch_1_lesson_emily_xia.py b/ch_1_lesson_emily_xia.py new file mode 100644 index 0000000..3d12fb4 --- /dev/null +++ b/ch_1_lesson_emily_xia.py @@ -0,0 +1 @@ +print ('Hello, world') From 01f5a750cb25ed24ad5afbcca32d0d1786132dd7 Mon Sep 17 00:00:00 2001 From: emxia18 <55220044+emxia18@users.noreply.github.com> Date: Sat, 14 Sep 2019 20:03:08 -0700 Subject: [PATCH 02/25] Add files via upload add ch_1_assign_emily_xia.py --- ch-1_assign_emily_xia.py | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ch-1_assign_emily_xia.py diff --git a/ch-1_assign_emily_xia.py b/ch-1_assign_emily_xia.py new file mode 100644 index 0000000..bce959e --- /dev/null +++ b/ch-1_assign_emily_xia.py @@ -0,0 +1,90 @@ +teams_dictionary={ + 1678:{ + "Location":"Davis_CA", + "Rookie_year":2005, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Central_Valley_Regional", + "Sacramento_Regional", + "Aerospace_Valley_Regional", + "Carver_Division", + "Einstein_Field", + "RCC_Qianjiang_International_Robotics_Invitational", + "Chezy_Champs"], + "Competition_Location":[ + "Fresno_CA", + "Davis_CA", + "Lancaster_CA", + "Houston_TX", + "Houston_TX", + "Hangzhou_CN", + "San_Jose_CA"], + "Competition_Awards":[ + "Regional_Chairmans_Award", + "Regional_Winner", + "Deans_List", + "Regional_Winner", + "Industrial_Design_Award", + "Excellence_in_Engineering", + "Championship_Subdivision_Winner", + "Entrepreneurship-Award"]}, + 3132:{ + "Location":"Sydney_Australia", + "Rookie_year":2010, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Southern_Cross_Regional", + "South_Pacific_Regional", + "Carver_Division", + "Einstein_Field"], + "Competition_Location":[ + "Sydeny_Olympic_Park", + "Sydeny_Olympic_Park", + "Houston_TX", + "Houston_TX"], + "Competition_Awards":[ + "Woodie_Flowers", + "Gracious_Professionalism", + "Regional_Engineering_Inspiration", + "Safety_Award"]}, + 1902:{ + "Location":"Orlando_FL", + "Rookie_year":2006, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Palmetto_Regional", + "Orlando_Regional", + "Newton_Division", + "Einstein_Field"], + "Competition_Location":[ + "Myrtle_Beach", + "Orlando_FL", + "Houston_TX", + "Houston_TX"], + "Competition_Awards":[ + "Regional_Chairmans_Award", + "Deans_List", + "Entrepreneurship-Award", + "Chairmans_Award_Finalist"]}, + 5458:{ + "Location":"Woodland_CA", + "Rookie_year":2015, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Central_Valley_Regional", + "Sacramento_Regional"], + "Competition_Location":[ + "Fresno_CA", + "Davis_CA"], + "Competition_Awards":[ + "None"]}, + 6174:{ + "Location":"Winters_CA", + "Rookie_year":2016, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Sacramento_Regional"], + "Competition_Location":[ + "Davis_CA"], + "Competition_Awards":[ + "None"]}} From d46025d30c88e70a0cb8c493975deccc53c26804 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Sun, 15 Sep 2019 20:23:17 -0700 Subject: [PATCH 03/25] add ch_1_assign_emily_xia.py to repository --- ch_1_assign_emily_xia.py | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ch_1_assign_emily_xia.py diff --git a/ch_1_assign_emily_xia.py b/ch_1_assign_emily_xia.py new file mode 100644 index 0000000..98cac4a --- /dev/null +++ b/ch_1_assign_emily_xia.py @@ -0,0 +1,90 @@ +teams_dictionary={ + 1678:{ + "Location":"Davis_CA", + "Rookie_year":2005, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Central_Valley_Regional", + "Sacramento_Regional", + "Aerospace_Valley_Regional", + "Carver_Division", + "Einstein_Field", + "RCC_Qianjiang_International_Robotics_Invitational", + "Chezy_Champs"], + "Competition_Location":[ + "Fresno_CA", + "Davis_CA", + "Lancaster_CA", + "Houston_TX", + "Houston_TX", + "Hangzhou_CN", + "San_Jose_CA"], + "Competition_Awards":[ + "Regional_Chairmans_Award", + "Regional_Winner", + "Deans_List", + "Regional_Winner", + "Industrial_Design_Award", + "Excellence_in_Engineering", + "Championship_Subdivision_Winner", + "Entrepreneurship-Award"]}, + 3132:{ + "Location":"Sydney_Australia", + "Rookie_year":2010, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Southern_Cross_Regional", + "South_Pacific_Regional", + "Carver_Division", + "Einstein_Field"], + "Competition_Location":[ + "Sydeny_Olympic_Park", + "Sydeny_Olympic_Park", + "Houston_TX", + "Houston_TX"], + "Competition_Awards":[ + "Woodie_Flowers", + "Gracious_Professionalism", + "Regional_Engineering_Inspiration", + "Safety_Award"]}, + 1902:{ + "Location":"Orlando_FL", + "Rookie_year":2006, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Palmetto_Regional", + "Orlando_Regional", + "Newton_Division", + "Einstein_Field"], + "Competition_Location":[ + "Myrtle_Beach", + "Orlando_FL", + "Houston_TX", + "Houston_TX"], + "Competition_Awards":[ + "Regional_Chairmans_Award", + "Deans_List", + "Entrepreneurship-Award", + "Chairmans_Award_Finalist"]}, + 5458:{ + "Location":"Woodland_CA", + "Rookie_year":2015, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Central_Valley_Regional", + "Sacramento_Regional"], + "Competition_Location":[ + "Fresno_CA", + "Davis_CA"], + "Competition_Awards":[ + "None"]}, + 6174:{ + "Location":"Winters_CA", + "Rookie_year":2016, + "2019_Competition_Status":True, + "Names_of_Competions":[ + "Sacramento_Regional"], + "Competition_Location":[ + "Davis_CA"], + "Competition_Awards":[ + "None"]}} \ No newline at end of file From 0e42bc47cd64e23777c43c0d12902fc8ffe110ef Mon Sep 17 00:00:00 2001 From: emxia18 Date: Sat, 21 Sep 2019 18:04:56 -0700 Subject: [PATCH 04/25] add lines 91-93 on ch_1_assign_emily_xia.py --- ch_1_assign_emily_xia.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ch_1_assign_emily_xia.py b/ch_1_assign_emily_xia.py index 98cac4a..02fbb53 100644 --- a/ch_1_assign_emily_xia.py +++ b/ch_1_assign_emily_xia.py @@ -87,4 +87,7 @@ "Competition_Location":[ "Davis_CA"], "Competition_Awards":[ - "None"]}} \ No newline at end of file + "None"]}} +team_number=int(input("What is the number of the desired team?")) +team_attribute=str(input("What is the desired attribute?")) +print(teams_dictionary[team_number][team_attribute]) \ No newline at end of file From ee89495135ef51129f7cc8822fb36abbaa630259 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 25 Sep 2019 19:11:16 -0700 Subject: [PATCH 05/25] edit lines 91-101 --- ch_1_assign_emily_xia.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ch_1_assign_emily_xia.py b/ch_1_assign_emily_xia.py index 02fbb53..eb689c7 100644 --- a/ch_1_assign_emily_xia.py +++ b/ch_1_assign_emily_xia.py @@ -88,6 +88,14 @@ "Davis_CA"], "Competition_Awards":[ "None"]}} -team_number=int(input("What is the number of the desired team?")) -team_attribute=str(input("What is the desired attribute?")) +team_number = int(input("Out of 1678, 3132, 1902, 5458, and 6174, what is the number of the desired team?")) +team_attribute = str(input( + """Out of: + Location, + Rookie_year, + 2019_Competition_Status, + Names_of_Competitions, + Competition_Locations, + Competition_Awards + what is the desired attribute?""")) print(teams_dictionary[team_number][team_attribute]) \ No newline at end of file From 6a1d829621ffe1eb33d8b1c05d19a71c38544f8e Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 26 Sep 2019 19:02:04 -0700 Subject: [PATCH 06/25] combine two lists: "Names_of_Competition" and "Competition_Location" into one dictionary --- ch_2_assign_emily_xia.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ch_2_assign_emily_xia.py diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py new file mode 100644 index 0000000..f12f791 --- /dev/null +++ b/ch_2_assign_emily_xia.py @@ -0,0 +1,43 @@ +team_dictionary = {} +user_input = "yeet" +user_action = input("""What action do you want to take: + add a team, + view a team's information, + remove a team, + search for a team, + list all teams, + or return to main menu? \n""") +if user_action == "add a team": + while user_input != "nah": + number = int(input("What is your team number? \n")) + name = str(input("What is the name of your team? \n")) + programming_language = str(input("What is the programming language of your team? \n")) + width = int(input("What is the width of your robot? \n")) + length = int(input("What is the length of your robot? \n")) + camera_vision_system = bool(input("True or False, your robot has a camera vision system? \n")) + number_of_motors = int(input("How many motors does your robot have? \n")) + added_team_information = { + "number": number, + "name": name, + "programming_language": programming_language, + "width": width, + "length": length, + "camera_vision_system": camera_vision_system, + "number_of_motors": number_of_motors} + team_dictionary.update({number:added_team_information}) + print(team_dictionary) + user_input = input("Do you want to continue? yeet or nah? \n") +if user_input == "nah": + user_action = input("""What action do you want to take: + add a team, + view a team's information, + remove a team, + search for a team, + list all teams, + or return to main menu? \n""") +elif user_action == "view a team's information": + view_team = int(input("What is the number of the team you want to view?")) + print(team_dictionary[view_team]) + + + From 8fc0c842a19df8567fb02abc2870e6d3d73c0a3d Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 26 Sep 2019 19:50:06 -0700 Subject: [PATCH 07/25] write the code --- ch_2_assign_emily_xia.py | 66 ++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index f12f791..8a89db1 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -1,14 +1,16 @@ team_dictionary = {} -user_input = "yeet" +user_input_add = "yeet" +user_input_view = "yeet" +user_input_remove = "yeet" +user_input_list = "yeet" user_action = input("""What action do you want to take: add a team, view a team's information, remove a team, search for a team, - list all teams, - or return to main menu? \n""") + list all teams? \n""") if user_action == "add a team": - while user_input != "nah": + while user_input_add != "nah": number = int(input("What is your team number? \n")) name = str(input("What is the name of your team? \n")) programming_language = str(input("What is the programming language of your team? \n")) @@ -26,18 +28,44 @@ "number_of_motors": number_of_motors} team_dictionary.update({number:added_team_information}) print(team_dictionary) - user_input = input("Do you want to continue? yeet or nah? \n") -if user_input == "nah": - user_action = input("""What action do you want to take: - add a team, - view a team's information, - remove a team, - search for a team, - list all teams, - or return to main menu? \n""") -elif user_action == "view a team's information": - view_team = int(input("What is the number of the team you want to view?")) - print(team_dictionary[view_team]) - - - + user_input_add = input("Do you want to continue? yeet or nah? \n") + if user_input_add == "nah": + user_action = input("""What action do you want to take: + add a team, + view a team's information, + remove a team, + list all teams? \n""") +if user_action == "view a team's information": + while user_input_view != "nah": + view_team = int(input("What is the number of the team you want to view?")) + print(team_dictionary[view_team]) + user_input_view = input("Do you want to coninue? yeet or nah? \n") + if user_input_view == "nah": + user_action = input("""What action do you want to take: + add a team, + view a team's information, + remove a team, + list all teams? \n""") +if user_action == "remove a team": + while user_input_remove != "nah": + print(team_dictionary) + remove_team = int(input("What team do you want to remove? \n ")) + team_dictionary.pop(remove_team) + print(team_dictionary) + user_input_remove = input("Do you want to continue? yeet or nah? \n") + if user_input_remove == "nah": + user_action = input("""What action do you want to take: + add a team, + view a team's information, + remove a team, + list all teams? \n""") +if user_action == "list all teams": + while user_input_list != "nah": + print(team_dictionary) + user_input_list = input("Do you want to continue? yeet or nah? \n") + if user_input_list == "nah": + user_action = input("""What action do you want to take: + add a team, + view a team's information, + remove a team, + list all teams? \n""") From 5c6ead934e86cec49288f811b38524fe8ebc082d Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 26 Sep 2019 20:34:39 -0700 Subject: [PATCH 08/25] add modified version of ch_2_assign_emily_xia.py --- ch_2_assign_emily_xia_2.py | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ch_2_assign_emily_xia_2.py diff --git a/ch_2_assign_emily_xia_2.py b/ch_2_assign_emily_xia_2.py new file mode 100644 index 0000000..7ff19f8 --- /dev/null +++ b/ch_2_assign_emily_xia_2.py @@ -0,0 +1,53 @@ +team_dictionary = {} +user_action = int(input("""Enter the number of the action you want to do + 1 add a team + 2 view a team + 3 remove a team + 4 list all teams \n """)) +while True: + if user_action == 0: + user_action = int(input("""Enter the number of the action you want to do + 1 add a team + 2 view a team + 3 remove a team + 4 list all teams \n """)) + elif user_action == 1: + number = int(input("What is your team number? \n")) + name = str(input("What is the name of your team? \n")) + programming_language = str(input("What is the programming language of your team? \n")) + width = int(input("What is the width of your robot? \n")) + length = int(input("What is the length of your robot? \n")) + camera_vision_system = bool(input("True or False, your robot has a camera vision system? \n")) + number_of_motors = int(input("How many motors does your robot have? \n")) + added_team_information = { + "number": number, + "name": name, + "programming_language": programming_language, + "width": width, + "length": length, + "camera_vision_system": camera_vision_system, + "number_of_motors": number_of_motors} + team_dictionary.update({number:added_team_information}) + print(team_dictionary) + user_action = int(input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """)) + elif user_action == 2: + view_team = int(input("What is the number of the team you want to view? \n ")) + print(team_dictionary[view_team]) + user_action = int(input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """)) + elif user_action == 3: + print(team_dictionary) + remove_team = int(input("What is the number of the team you want to remove? \n ")) + team_dictionary.pop(remove_team) + print("Team" +remove_team+ "has been removed from the team dictionary!") + user_action = int(input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """)) + elif user_action == 4: + print(team_dictionary) + user_action = int(input("""If you want to continue, press 4. \nIf you want to exit the "list" function, press 0. \n """)) + elif user_action not in [0, 1, 2, 3, 4]: + print("I'm sorry, could you please re-enter your command?") + user_action = int(input("""Enter the number of the action you want to do + 1 add a team + 2 view a team + 3 remove a team + 4 search a team + 5 list all teams \n""")) \ No newline at end of file From 1bdd0f102bdd6c6ec2ffbe419b86b7da96b589af Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 26 Sep 2019 20:47:01 -0700 Subject: [PATCH 09/25] add comments and improve code --- ch_2_assign_emily_xia_2.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ch_2_assign_emily_xia_2.py b/ch_2_assign_emily_xia_2.py index 7ff19f8..333b974 100644 --- a/ch_2_assign_emily_xia_2.py +++ b/ch_2_assign_emily_xia_2.py @@ -6,12 +6,14 @@ 4 list all teams \n """)) while True: if user_action == 0: + #returning to main menu user_action = int(input("""Enter the number of the action you want to do 1 add a team 2 view a team 3 remove a team 4 list all teams \n """)) - elif user_action == 1: + elif user_action == 1: + #adding a team number = int(input("What is your team number? \n")) name = str(input("What is the name of your team? \n")) programming_language = str(input("What is the programming language of your team? \n")) @@ -31,19 +33,31 @@ print(team_dictionary) user_action = int(input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """)) elif user_action == 2: + #viewing a team view_team = int(input("What is the number of the team you want to view? \n ")) - print(team_dictionary[view_team]) + if view_team in team_dictionary == True: + print(team_dictionary[view_team]) + if view_team in team_dictionary == False: + print("I'm sorry, the team you are looking for does not exist.") + view_team = int(input("What is the number of the team you want to view? \n ")) user_action = int(input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """)) elif user_action == 3: + #removing a team print(team_dictionary) remove_team = int(input("What is the number of the team you want to remove? \n ")) - team_dictionary.pop(remove_team) - print("Team" +remove_team+ "has been removed from the team dictionary!") + if remove_team in team_dictionary == True: + team_dictionary.pop(remove_team) + print("Team" +remove_team+ "has been removed from the team dictionary!") + if remove_team in team_dictionary == False: + print("I'm sorry, the team you are looking for does not exist.") + remove_team = int(input("What is the number of the team you want to view? \n ")) user_action = int(input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """)) elif user_action == 4: + #listing all teams print(team_dictionary) user_action = int(input("""If you want to continue, press 4. \nIf you want to exit the "list" function, press 0. \n """)) elif user_action not in [0, 1, 2, 3, 4]: + #returning to main menu if user_action is not a known value print("I'm sorry, could you please re-enter your command?") user_action = int(input("""Enter the number of the action you want to do 1 add a team From 1fc36f4ea0cd8489bdb6d2f59427936548eb0daa Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 2 Oct 2019 18:51:34 -0700 Subject: [PATCH 10/25] add search function --- ch_2_assign_emily_xia.py | 115 +++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 8a89db1..753f656 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -1,16 +1,23 @@ team_dictionary = {} -user_input_add = "yeet" -user_input_view = "yeet" -user_input_remove = "yeet" -user_input_list = "yeet" -user_action = input("""What action do you want to take: - add a team, - view a team's information, - remove a team, - search for a team, - list all teams? \n""") -if user_action == "add a team": - while user_input_add != "nah": +user_action = int(input("""Enter the number of the action you want to do + 1 add a team + 2 view a team + 3 remove a team + 4 search a team + 5 list all teams + 6 leave\n """)) +while True: + if user_action == 0: + #returning to main menu + user_action = int(input("""Enter the number of the action you want to do + 1 add a team + 2 view a team + 3 remove a team + 4 search a team + 5 list all teams + 6 leave \n """)) + elif user_action == 1: + #adding a team number = int(input("What is your team number? \n")) name = str(input("What is the name of your team? \n")) programming_language = str(input("What is the programming language of your team? \n")) @@ -27,45 +34,49 @@ "camera_vision_system": camera_vision_system, "number_of_motors": number_of_motors} team_dictionary.update({number:added_team_information}) - print(team_dictionary) - user_input_add = input("Do you want to continue? yeet or nah? \n") - if user_input_add == "nah": - user_action = input("""What action do you want to take: - add a team, - view a team's information, - remove a team, - list all teams? \n""") -if user_action == "view a team's information": - while user_input_view != "nah": - view_team = int(input("What is the number of the team you want to view?")) - print(team_dictionary[view_team]) - user_input_view = input("Do you want to coninue? yeet or nah? \n") - if user_input_view == "nah": - user_action = input("""What action do you want to take: - add a team, - view a team's information, - remove a team, - list all teams? \n""") -if user_action == "remove a team": - while user_input_remove != "nah": + print("\nAdded " + str(team_dictionary[number][number])) + user_action = int(input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """)) + elif user_action == 2: + #viewing a team + view_team = int(input("What is the number of the team you want to view? \n ")) + if view_team in team_dictionary == True: + print(team_dictionary[view_team]) + if view_team in team_dictionary == False: + print("I'm sorry, the team you are looking for does not exist.") + view_team = int(input("What is the number of the team you want to view? \n ")) + user_action = int(input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """)) + elif user_action == 3: + #removing a team print(team_dictionary) - remove_team = int(input("What team do you want to remove? \n ")) - team_dictionary.pop(remove_team) + remove_team = int(input("What is the number of the team you want to remove? \n ")) + if remove_team in team_dictionary == True: + team_dictionary.pop(remove_team) + print("Team" +remove_team+ "has been removed from the team dictionary!") + if remove_team in team_dictionary == False: + print("I'm sorry, the team you are looking for does not exist.") + remove_team = int(input("What is the number of the team you want to view? \n ")) + user_action = int(input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """)) + elif user_action == 4: + #searching for a team + search_team = int(input("What is the number of the team you want to search for? \n")) + if search_team in team_dictionary == True: + print("Yes," +search_team "is in the team dictionary") + if search_team in team_dictionary == False: + print("I'm sorry, but" +search_team "is not in the team dictionary") + user_action = int(input("""If you want to continue, press 4. \n If you want to exit the "search" function, press 0. \n """)) + elif user_action == 5: + #listing all teams print(team_dictionary) - user_input_remove = input("Do you want to continue? yeet or nah? \n") - if user_input_remove == "nah": - user_action = input("""What action do you want to take: - add a team, - view a team's information, - remove a team, - list all teams? \n""") -if user_action == "list all teams": - while user_input_list != "nah": - print(team_dictionary) - user_input_list = input("Do you want to continue? yeet or nah? \n") - if user_input_list == "nah": - user_action = input("""What action do you want to take: - add a team, - view a team's information, - remove a team, - list all teams? \n""") + user_action = int(input("""If you want to continue, press 5. \nIf you want to exit the "list" function, press 0. \n """)) + elif user_action not in [0, 1, 2, 3, 4, 5, 6]: + #returning to main menu if user_action is not a known value + print("I'm sorry, could you please re-enter your command?") + user_action = int(input("""Enter the number of the action you want to do + 1 add a team + 2 view a team + 3 remove a team + 4 search a team + 5 list all teams + 6 leave \n""")) + elif user_action == 6: + break \ No newline at end of file From 87aaf3aa8476f6c6439e8af4e25ca617ba2c80a2 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 2 Oct 2019 20:48:32 -0700 Subject: [PATCH 11/25] add validation in search function --- ch_2_assign_emily_xia.py | 71 +++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 753f656..37be015 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -1,24 +1,24 @@ team_dictionary = {} -user_action = int(input("""Enter the number of the action you want to do +user_action = input("""Enter the number of the action you want to do 1 add a team 2 view a team 3 remove a team 4 search a team 5 list all teams - 6 leave\n """)) + 6 leave \n """) while True: - if user_action == 0: + if user_action == "0": #returning to main menu - user_action = int(input("""Enter the number of the action you want to do + user_action = input("""Enter the number of the action you want to do 1 add a team 2 view a team 3 remove a team 4 search a team 5 list all teams - 6 leave \n """)) - elif user_action == 1: + 6 leave \n """) + elif user_action == "1": #adding a team - number = int(input("What is your team number? \n")) + number = input("What is your team number? \n") name = str(input("What is the name of your team? \n")) programming_language = str(input("What is the programming language of your team? \n")) width = int(input("What is the width of your robot? \n")) @@ -34,49 +34,54 @@ "camera_vision_system": camera_vision_system, "number_of_motors": number_of_motors} team_dictionary.update({number:added_team_information}) - print("\nAdded " + str(team_dictionary[number][number])) - user_action = int(input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """)) - elif user_action == 2: + user_action = input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """) + elif user_action == "2": #viewing a team view_team = int(input("What is the number of the team you want to view? \n ")) - if view_team in team_dictionary == True: + if view_team in team_dictionary: print(team_dictionary[view_team]) - if view_team in team_dictionary == False: + elif view_team not in team_dictionary: print("I'm sorry, the team you are looking for does not exist.") - view_team = int(input("What is the number of the team you want to view? \n ")) - user_action = int(input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """)) - elif user_action == 3: + user_action = input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """) + elif user_action == "3": #removing a team print(team_dictionary) remove_team = int(input("What is the number of the team you want to remove? \n ")) - if remove_team in team_dictionary == True: + if remove_team in team_dictionary: team_dictionary.pop(remove_team) print("Team" +remove_team+ "has been removed from the team dictionary!") - if remove_team in team_dictionary == False: + elif remove_team not in team_dictionary: print("I'm sorry, the team you are looking for does not exist.") - remove_team = int(input("What is the number of the team you want to view? \n ")) - user_action = int(input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """)) - elif user_action == 4: + user_action = input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """) + elif user_action == "4": #searching for a team - search_team = int(input("What is the number of the team you want to search for? \n")) - if search_team in team_dictionary == True: - print("Yes," +search_team "is in the team dictionary") - if search_team in team_dictionary == False: - print("I'm sorry, but" +search_team "is not in the team dictionary") - user_action = int(input("""If you want to continue, press 4. \n If you want to exit the "search" function, press 0. \n """)) - elif user_action == 5: + search_team = input("What is the number of the team you want to search for? \n") + if search_team in team_dictionary: + print("Yes, the team you are looking for is in the team dictionary") + else: + result=None + for key in team_dictionary: + if team_dictionary[key]["name"] == search_team: + print("Yes, the team you are looking for is in the team dictionary") + result=team_dictionary[key] + break + if not result: + print("""I'm sorry, but the team you are looking for is not in the team dictionary. + Please make sure that your input is an integer.""") + user_action = input("""If you want to continue, press 4. \n If you want to exit the "search" function, press 0. \n """) + elif user_action == "5": #listing all teams print(team_dictionary) - user_action = int(input("""If you want to continue, press 5. \nIf you want to exit the "list" function, press 0. \n """)) - elif user_action not in [0, 1, 2, 3, 4, 5, 6]: + user_action = input("""If you want to continue, press 5. \nIf you want to exit the "list" function, press 0. \n """) + elif user_action not in ["0", "1", "2", "3", "4", "5", "6"]: #returning to main menu if user_action is not a known value print("I'm sorry, could you please re-enter your command?") - user_action = int(input("""Enter the number of the action you want to do + user_action = input("""Enter the number of the action you want to do 1 add a team 2 view a team 3 remove a team 4 search a team 5 list all teams - 6 leave \n""")) - elif user_action == 6: - break \ No newline at end of file + 6 leave \n""") + elif user_action == "6": + break From 1cc9abd5965eb98c4a4948c5d4949e2c1140a1ca Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 3 Oct 2019 19:13:12 -0700 Subject: [PATCH 12/25] delete string, integer, etc from add part to prevent code from crashing~ --- ch_2_assign_emily_xia.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 37be015..458708c 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -19,12 +19,12 @@ elif user_action == "1": #adding a team number = input("What is your team number? \n") - name = str(input("What is the name of your team? \n")) - programming_language = str(input("What is the programming language of your team? \n")) - width = int(input("What is the width of your robot? \n")) - length = int(input("What is the length of your robot? \n")) - camera_vision_system = bool(input("True or False, your robot has a camera vision system? \n")) - number_of_motors = int(input("How many motors does your robot have? \n")) + name = input("What is the name of your team? \n") + programming_language = input("What is the programming language of your team? \n") + width = input("What is the width of your robot? \n") + length = input("What is the length of your robot? \n") + camera_vision_system = input("True or False, your robot has a camera vision system? \n") + number_of_motors = input("How many motors does your robot have? \n") added_team_information = { "number": number, "name": name, From 0a56a38a1104fa3501884e1c3214e72c0165190b Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 3 Oct 2019 19:34:25 -0700 Subject: [PATCH 13/25] remove extra file --- ch_2_assign_emily_xia_2.py | 67 -------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 ch_2_assign_emily_xia_2.py diff --git a/ch_2_assign_emily_xia_2.py b/ch_2_assign_emily_xia_2.py deleted file mode 100644 index 333b974..0000000 --- a/ch_2_assign_emily_xia_2.py +++ /dev/null @@ -1,67 +0,0 @@ -team_dictionary = {} -user_action = int(input("""Enter the number of the action you want to do - 1 add a team - 2 view a team - 3 remove a team - 4 list all teams \n """)) -while True: - if user_action == 0: - #returning to main menu - user_action = int(input("""Enter the number of the action you want to do - 1 add a team - 2 view a team - 3 remove a team - 4 list all teams \n """)) - elif user_action == 1: - #adding a team - number = int(input("What is your team number? \n")) - name = str(input("What is the name of your team? \n")) - programming_language = str(input("What is the programming language of your team? \n")) - width = int(input("What is the width of your robot? \n")) - length = int(input("What is the length of your robot? \n")) - camera_vision_system = bool(input("True or False, your robot has a camera vision system? \n")) - number_of_motors = int(input("How many motors does your robot have? \n")) - added_team_information = { - "number": number, - "name": name, - "programming_language": programming_language, - "width": width, - "length": length, - "camera_vision_system": camera_vision_system, - "number_of_motors": number_of_motors} - team_dictionary.update({number:added_team_information}) - print(team_dictionary) - user_action = int(input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """)) - elif user_action == 2: - #viewing a team - view_team = int(input("What is the number of the team you want to view? \n ")) - if view_team in team_dictionary == True: - print(team_dictionary[view_team]) - if view_team in team_dictionary == False: - print("I'm sorry, the team you are looking for does not exist.") - view_team = int(input("What is the number of the team you want to view? \n ")) - user_action = int(input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """)) - elif user_action == 3: - #removing a team - print(team_dictionary) - remove_team = int(input("What is the number of the team you want to remove? \n ")) - if remove_team in team_dictionary == True: - team_dictionary.pop(remove_team) - print("Team" +remove_team+ "has been removed from the team dictionary!") - if remove_team in team_dictionary == False: - print("I'm sorry, the team you are looking for does not exist.") - remove_team = int(input("What is the number of the team you want to view? \n ")) - user_action = int(input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """)) - elif user_action == 4: - #listing all teams - print(team_dictionary) - user_action = int(input("""If you want to continue, press 4. \nIf you want to exit the "list" function, press 0. \n """)) - elif user_action not in [0, 1, 2, 3, 4]: - #returning to main menu if user_action is not a known value - print("I'm sorry, could you please re-enter your command?") - user_action = int(input("""Enter the number of the action you want to do - 1 add a team - 2 view a team - 3 remove a team - 4 search a team - 5 list all teams \n""")) \ No newline at end of file From dd81089f580f33930d32e0ea250001b7c4e8f6e0 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Thu, 3 Oct 2019 20:46:43 -0700 Subject: [PATCH 14/25] add modify function --- ch_2_assign_emily_xia.py | 190 ++++++++++++++++++++++----------------- 1 file changed, 106 insertions(+), 84 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 458708c..75989a6 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -1,87 +1,109 @@ team_dictionary = {} user_action = input("""Enter the number of the action you want to do - 1 add a team - 2 view a team - 3 remove a team - 4 search a team - 5 list all teams - 6 leave \n """) + 1 add a team + 2 modify a team + 3 view a team + 4 remove a team + 5 search a team + 6 list all teams + 7 leave \n """) while True: - if user_action == "0": - #returning to main menu - user_action = input("""Enter the number of the action you want to do - 1 add a team - 2 view a team - 3 remove a team - 4 search a team - 5 list all teams - 6 leave \n """) - elif user_action == "1": - #adding a team - number = input("What is your team number? \n") - name = input("What is the name of your team? \n") - programming_language = input("What is the programming language of your team? \n") - width = input("What is the width of your robot? \n") - length = input("What is the length of your robot? \n") - camera_vision_system = input("True or False, your robot has a camera vision system? \n") - number_of_motors = input("How many motors does your robot have? \n") - added_team_information = { - "number": number, - "name": name, - "programming_language": programming_language, - "width": width, - "length": length, - "camera_vision_system": camera_vision_system, - "number_of_motors": number_of_motors} - team_dictionary.update({number:added_team_information}) - user_action = input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """) - elif user_action == "2": - #viewing a team - view_team = int(input("What is the number of the team you want to view? \n ")) - if view_team in team_dictionary: - print(team_dictionary[view_team]) - elif view_team not in team_dictionary: - print("I'm sorry, the team you are looking for does not exist.") - user_action = input("""If you want to continue, press 2. \nIf you want to exit the "view" function, press 0. \n """) - elif user_action == "3": - #removing a team - print(team_dictionary) - remove_team = int(input("What is the number of the team you want to remove? \n ")) - if remove_team in team_dictionary: - team_dictionary.pop(remove_team) - print("Team" +remove_team+ "has been removed from the team dictionary!") - elif remove_team not in team_dictionary: - print("I'm sorry, the team you are looking for does not exist.") - user_action = input("""If you want to continue, press 3. \nIf you want to exit the "remove" function, press 0. \n """) - elif user_action == "4": - #searching for a team - search_team = input("What is the number of the team you want to search for? \n") - if search_team in team_dictionary: - print("Yes, the team you are looking for is in the team dictionary") - else: - result=None - for key in team_dictionary: - if team_dictionary[key]["name"] == search_team: - print("Yes, the team you are looking for is in the team dictionary") - result=team_dictionary[key] - break - if not result: - print("""I'm sorry, but the team you are looking for is not in the team dictionary. - Please make sure that your input is an integer.""") - user_action = input("""If you want to continue, press 4. \n If you want to exit the "search" function, press 0. \n """) - elif user_action == "5": - #listing all teams - print(team_dictionary) - user_action = input("""If you want to continue, press 5. \nIf you want to exit the "list" function, press 0. \n """) - elif user_action not in ["0", "1", "2", "3", "4", "5", "6"]: - #returning to main menu if user_action is not a known value - print("I'm sorry, could you please re-enter your command?") - user_action = input("""Enter the number of the action you want to do - 1 add a team - 2 view a team - 3 remove a team - 4 search a team - 5 list all teams - 6 leave \n""") - elif user_action == "6": - break + if user_action == "0": + #returning to main menu + user_action = input("""Enter the number of the action you want to do + 1 add a team + 2 modify a team + 3 view a team + 4 remove a team + 5 search a team + 6 list all teams + 7 leave \n """) + elif user_action == "1": + #adding a team + number = input("What is your team number? \n") + name = input("What is the name of your team? \n") + programming_language = input("What is the programming language of your team? \n") + width = input("What is the width of your robot? \n") + length = input("What is the length of your robot? \n") + camera_vision_system = input("True or False, your robot has a camera vision system? \n") + number_of_motors = input("How many motors does your robot have? \n") + added_team_information = { + "number": number, + "name": name, + "programming_language": programming_language, + "width": width, + "length": length, + "camera_vision_system": camera_vision_system, + "number_of_motors": number_of_motors} + team_dictionary.update({number:added_team_information}) + user_action = input("""If you want to continue, press 1. \nIf you want to exit the "add" function, press 0. \n """) + elif user_action == "2": + #modify a team + modify_team = input("What is the team you want to modify? \n") + modify_attribute = None + new_attribute = None + if modify_team in team_dictionary: + print(team_dictionary[modify_team]) + modify_attribute = input("What is the attribute that you want to modify? \n") + if modify_attribute in team_dictionary[modify_team]: + new_attribute = input("What do you want the new "+modify_attribute+" to be? \n") + team_dictionary.update({modify_team:{modify_attribute:new_attribute}}) + print(team_dictionary[modify_team]) + user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") + elif modify_team not in team_dictionary[modify_team]: + print("I'm sorry, the team you want to modify is not in the dictionary.") + user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") + elif modify_team not in team_dictionary: + print("I'm sorry, the team you want to modify is not in the dictionary.") + user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") + elif user_action == "3": + #viewing a team + view_team = int(input("What is the number of the team you want to view? \n ")) + if view_team in team_dictionary: + print(team_dictionary[view_team]) + elif view_team not in team_dictionary: + print("I'm sorry, the team you are looking for does not exist.") + user_action = input("""If you want to continue, press 3. \nIf you want to exit the "view" function, press 0. \n """) + elif user_action == "4": + #removing a team + print(team_dictionary) + remove_team = int(input("What is the number of the team you want to remove? \n ")) + if remove_team in team_dictionary: + team_dictionary.pop(remove_team) + print("Team" +remove_team+ "has been removed from the team dictionary!") + elif remove_team not in team_dictionary: + print("I'm sorry, the team you are looking for does not exist.") + user_action = input("""If you want to continue, press 4. \nIf you want to exit the "remove" function, press 0. \n """) + elif user_action == "5": + #searching for a team + search_team = input("What is the number of the team you want to search for? \n") + if search_team in team_dictionary: + print("Yes, the team you are looking for is in the team dictionary") + else: + result=None + for key in team_dictionary: + if team_dictionary[key]["name"] == search_team: + print("Yes, the team you are looking for is in the team dictionary") + result=team_dictionary[key] + break + if not result: + print("""I'm sorry, but the team you are looking for is not in the team dictionary. + Please make sure that your input is an integer.""") + user_action = input("""If you want to continue, press 5. \n If you want to exit the "search" function, press 0. \n """) + elif user_action == "6": + #listing all teams + print(team_dictionary) + user_action = input("""If you want to continue, press 6. \nIf you want to exit the "list" function, press 0. \n """) + elif user_action not in ["0", "1", "2", "3", "4", "5", "6", "7"]: + #returning to main menu if user_action is not a known value + print("I'm sorry, could you please re-enter your command?") + user_action = input("""Enter the number of the action you want to do + 1 add a team + 2 modify a team + 3 view a team + 4 remove a team + 5 search a team + 6 list all teams + 7 leave \n""") + elif user_action == "7": + break From f88971fad0db686620e81be50feed5e40ef817d1 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Mon, 14 Oct 2019 21:12:44 -0700 Subject: [PATCH 15/25] write code, some validation still needed --- ch_3_assign_emily_xia.py | 194 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 ch_3_assign_emily_xia.py diff --git a/ch_3_assign_emily_xia.py b/ch_3_assign_emily_xia.py new file mode 100644 index 0000000..6370985 --- /dev/null +++ b/ch_3_assign_emily_xia.py @@ -0,0 +1,194 @@ +team_dictionary={ + 1678:{ + "Location":"Davis_CA", + "Rookie_year":2005, + "2019_Competition_Status":True, + "Names_of_Competions":{ + "Central_Valley_Regional":"Fresno_CA", + "Sacramento_Regional":"Davis_CA", + "Aerospace_Valley_Regional":"Lancaster_CA", + "Carver_Division":"Houston_TX", + "Einstein_Field":"Houston_TX", + "RCC_Qianjiang_International_Robotics_Invitational":"Hangzhou_CN", + "Chezy_Champs":"San_Jose_CA"}, + "Competition_Awards":[ + "Regional_Chairmans_Award", + "Regional_Winner", + "Deans_List", + "Regional_Winner", + "Industrial_Design_Award", + "Excellence_in_Engineering", + "Championship_Subdivision_Winner", + "Entrepreneurship-Award"]}, + 3132:{ + "Location":"Sydney_Australia", + "Rookie_year":2010, + "2019_Competition_Status":True, + "Names_of_Competions":{ + "Southern_Cross_Regional":"Sydeny_Olympic_Park", + "South_Pacific_Regional":"Sydeny_Olympic_Park", + "Carver_Division":"Houston_TX", + "Einstein_Field":"Houston_TX"}, + "Competition_Awards":[ + "Woodie_Flowers", + "Gracious_Professionalism", + "Regional_Engineering_Inspiration", + "Safety_Award"]}, + 1902:{ + "Location":"Orlando_FL", + "Rookie_year":2006, + "2019_Competition_Status":True, + "Names_of_Competions":{ + "Palmetto_Regional":"Myrtle_Beach", + "Orlando_Regional":"Orlando_FL", + "Newton_Division":"Houston_TX", + "Einstein_Field":"Houston_TX"}, + "Competition_Awards":[ + "Regional_Chairmans_Award", + "Deans_List", + "Entrepreneurship-Award", + "Chairmans_Award_Finalist"]}, + 5458:{ + "Location":"Woodland_CA", + "Rookie_year":2015, + "2019_Competition_Status":True, + "Names_of_Competions":{ + "Central_Valley_Regional":"Fresno_CA", + "Sacramento_Regional":"Davis_CA"}, + "Competition_Awards":[ + "None"]}, + 6174:{ + "Location":"Winters_CA", + "Rookie_year":2016, + "2019_Competition_Status":True, + "Names_of_Competions":{ + "Sacramento_Regional":"Davis_CA"}, + "Competition_Awards":[ + "None"]}} + +main_menu = """\nEnter the number of the action you want to do + 0 return to main menu + 1 add a team + 2 modify a team + 3 view a team + 4 remove a team + 5 search a team + 6 list all teams + 7 leave \n """ +def defining_team_number(): + return input("Enter the number of your team \n") +def get_user_action(): + return int(input(main_menu)) +def new_action(): + return input() +def not_available(): + print("I'm sorry the information you are looking for is not available") +def number_validation(): + return team_number.isdigit() +def team_number_validation(): + return team_number in team_dictionary + +user_action = get_user_action() +while True: + if user_action == 0: + #return to main menu + user_action = get_user_action() + elif user_action == 1: + #add a team + team_number = defining_team_number() + if number_validation() == True: + team_number = int(team_number) + if team_number_validation() == False: + team_name = input("What is the name of your team? \n") + programming_language = input("What is the programming language of your team? \n") + width = input("What is the width of your robot? \n") + length = input("What is the length of your robot? \n") + camera_vision_system = input("True or False, your robot has a camera vision system? \n") + number_of_motors = input("How many motors does your robot have? \n") + added_team_information = { + "number":team_number, + "name":team_name, + "programming_language": programming_language, + "width": width, + "length": length, + "camera_vision_system": camera_vision_system, + "number_of_motors": number_of_motors} + team_dictionary.update({team_number:added_team_information}) + user_action = get_user_action() + if team_number_validation() == True: + print("The team you want to add is already in the dictionary") + user_action = get_user_action() + elif number_validation() == False: + print("Your input is not an integer, please ensure that you input an integer") + team_number = defining_team_number() + elif user_action == 2: + #modify a team + team_number = defining_team_number() + if number_validation() == True: + team_number = int(team_number) + if team_number_validation() == True: + modify_attribute = input("What is the attribute that you want to modify?\n") + if modify_attribute in team_dictionary[team_number]: + new_attribute = input("What do you want the new " +modify_attribute+ "to be?\n") + team_dictionary.update({team_number:{modify_attribute:new_attribute}}) + print(team_dictionary[team_number]) + user_action = get_user_action() + elif modify_attribute not in team_dictionary[team_number]: + not_available() + user_action = get_user_action() + elif team_number_validation() == False: + not_available() + user_action = get_user_action() + elif number_validation() == False: + print("Your input is not an integer, please ensure that you input an integer") + team_number = defining_team_number() + elif user_action == 3: + #view a team + team_number = defining_team_number() + if number_validation() == True: + team_number = int(team_number) + if team_number_validation() == True: + print(team_dictionary[team_number]) + user_action = get_user_action() + elif team_number_validation() == False: + not_available() + user_action = get_user_action() + elif number_validation() == False: + print("Your input is not an integer, please ensure that you input an integer") + team_number = defining_team_number() + elif user_action == 4: + #remove a team + team_name = defining_team_number() + if number_validation() == True: + if team_number_validation() == True: + team_dictionary.pop(team_number) + user_action = get_user_action() + elif team_number_validation() == False: + not_available() + user_action = get_user_action() + elif number_validation() == False: + print("Your input is not an integer, please ensure that you input an integer") + team_number = defining_team_number() + elif user_action == 5: + #search a team + team_number = defining_team_number() + if number_validation() == + if team_number_validation() == True: + print(team_dictionary[team_number]) + user_action = get_user_action() + elif team_number_validation() == False: + not_available() + user_action = get_user_action() + elif user_action == 6: + #list all teams + for team_number, team_attributes in team_dictionary.items(): + print(team_number) + for key, value in team_attributes.items(): + print(f"{key}: {value}") + user_action = get_user_action() + elif user_action == 7: + #leave + break + elif user_action not in [1, 2, 3, 4, 5, 6, 7]: + not_available() + user_action = get_user_action() \ No newline at end of file From f29c1dc2cd1000f37c188ffc90d6ec05e74aaed8 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Tue, 15 Oct 2019 20:29:51 -0700 Subject: [PATCH 16/25] add verification, does not take into account first dictionary as part of the big dictionary --- ch_3_assign_emily_xia.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ch_3_assign_emily_xia.py b/ch_3_assign_emily_xia.py index 6370985..ab54db2 100644 --- a/ch_3_assign_emily_xia.py +++ b/ch_3_assign_emily_xia.py @@ -97,7 +97,7 @@ def team_number_validation(): #add a team team_number = defining_team_number() if number_validation() == True: - team_number = int(team_number) + team_number == int(team_number) if team_number_validation() == False: team_name = input("What is the name of your team? \n") programming_language = input("What is the programming language of your team? \n") @@ -115,7 +115,7 @@ def team_number_validation(): "number_of_motors": number_of_motors} team_dictionary.update({team_number:added_team_information}) user_action = get_user_action() - if team_number_validation() == True: + elif team_number_validation() == True: print("The team you want to add is already in the dictionary") user_action = get_user_action() elif number_validation() == False: @@ -125,7 +125,7 @@ def team_number_validation(): #modify a team team_number = defining_team_number() if number_validation() == True: - team_number = int(team_number) + team_number == int(team_number) if team_number_validation() == True: modify_attribute = input("What is the attribute that you want to modify?\n") if modify_attribute in team_dictionary[team_number]: @@ -146,7 +146,7 @@ def team_number_validation(): #view a team team_number = defining_team_number() if number_validation() == True: - team_number = int(team_number) + team_number == int(team_number) if team_number_validation() == True: print(team_dictionary[team_number]) user_action = get_user_action() @@ -160,6 +160,7 @@ def team_number_validation(): #remove a team team_name = defining_team_number() if number_validation() == True: + team_number == int(team_number) if team_number_validation() == True: team_dictionary.pop(team_number) user_action = get_user_action() @@ -172,13 +173,16 @@ def team_number_validation(): elif user_action == 5: #search a team team_number = defining_team_number() - if number_validation() == - if team_number_validation() == True: - print(team_dictionary[team_number]) - user_action = get_user_action() - elif team_number_validation() == False: - not_available() - user_action = get_user_action() + if number_validation() == True: + team_number == int(team_number) + if team_number_validation() == True: + print(team_dictionary[team_number]) + user_action = get_user_action() + elif team_number_validation() == False: + not_available() + user_action = get_user_action() + elif number_validation() == False: + print("Your input is not an integer, please ensure that you input an integer") elif user_action == 6: #list all teams for team_number, team_attributes in team_dictionary.items(): From 63634827360c34e01ce14f46107f4b0c752e3ef5 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 16 Oct 2019 19:54:28 -0700 Subject: [PATCH 17/25] improve validation --- ch_3_assign_emily_xia.py | 67 +++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/ch_3_assign_emily_xia.py b/ch_3_assign_emily_xia.py index ab54db2..52e2535 100644 --- a/ch_3_assign_emily_xia.py +++ b/ch_3_assign_emily_xia.py @@ -2,7 +2,7 @@ 1678:{ "Location":"Davis_CA", "Rookie_year":2005, - "2019_Competition_Status":True, + "Competition_Status_2019":True, "Names_of_Competions":{ "Central_Valley_Regional":"Fresno_CA", "Sacramento_Regional":"Davis_CA", @@ -23,7 +23,7 @@ 3132:{ "Location":"Sydney_Australia", "Rookie_year":2010, - "2019_Competition_Status":True, + "Competition_Status_2019":True, "Names_of_Competions":{ "Southern_Cross_Regional":"Sydeny_Olympic_Park", "South_Pacific_Regional":"Sydeny_Olympic_Park", @@ -37,7 +37,7 @@ 1902:{ "Location":"Orlando_FL", "Rookie_year":2006, - "2019_Competition_Status":True, + "Competition_Status-2019":True, "Names_of_Competions":{ "Palmetto_Regional":"Myrtle_Beach", "Orlando_Regional":"Orlando_FL", @@ -51,7 +51,7 @@ 5458:{ "Location":"Woodland_CA", "Rookie_year":2015, - "2019_Competition_Status":True, + "Competition_Status_2019":True, "Names_of_Competions":{ "Central_Valley_Regional":"Fresno_CA", "Sacramento_Regional":"Davis_CA"}, @@ -60,7 +60,7 @@ 6174:{ "Location":"Winters_CA", "Rookie_year":2016, - "2019_Competition_Status":True, + "Competition_Status_2019":True, "Names_of_Competions":{ "Sacramento_Regional":"Davis_CA"}, "Competition_Awards":[ @@ -85,8 +85,8 @@ def not_available(): print("I'm sorry the information you are looking for is not available") def number_validation(): return team_number.isdigit() -def team_number_validation(): - return team_number in team_dictionary +def team_number_validation(team): + return team in team_dictionary user_action = get_user_action() while True: @@ -97,25 +97,22 @@ def team_number_validation(): #add a team team_number = defining_team_number() if number_validation() == True: - team_number == int(team_number) - if team_number_validation() == False: - team_name = input("What is the name of your team? \n") - programming_language = input("What is the programming language of your team? \n") - width = input("What is the width of your robot? \n") - length = input("What is the length of your robot? \n") - camera_vision_system = input("True or False, your robot has a camera vision system? \n") - number_of_motors = input("How many motors does your robot have? \n") + team_number = int(team_number) + if team_number_validation(team_number) == False: + Location = input("What is the location of your team? \n") + Rookie_year = input("What is the rookie year of your team? \n") + Competition_Status_2019 = input("What is the 2019 competition status of your team? \n") + Names_of_Competions = input("What are the names of the competitions of your team? \n") + Competition_Awards = input("What are the names of the competition awards of your team? \n") added_team_information = { - "number":team_number, - "name":team_name, - "programming_language": programming_language, - "width": width, - "length": length, - "camera_vision_system": camera_vision_system, - "number_of_motors": number_of_motors} + "Location":Location, + "Rookie_year":Rookie_year, + "Competition_Status_2019": Competition_Status_2019, + "Names_of_Competitions": Names_of_Competitions, + "Competition_Awards": Competition_Awards} team_dictionary.update({team_number:added_team_information}) user_action = get_user_action() - elif team_number_validation() == True: + elif team_number_validation(team_number) == True: print("The team you want to add is already in the dictionary") user_action = get_user_action() elif number_validation() == False: @@ -125,8 +122,8 @@ def team_number_validation(): #modify a team team_number = defining_team_number() if number_validation() == True: - team_number == int(team_number) - if team_number_validation() == True: + team_number = int(team_number) + if team_number_validation(team_number) == True: modify_attribute = input("What is the attribute that you want to modify?\n") if modify_attribute in team_dictionary[team_number]: new_attribute = input("What do you want the new " +modify_attribute+ "to be?\n") @@ -136,7 +133,7 @@ def team_number_validation(): elif modify_attribute not in team_dictionary[team_number]: not_available() user_action = get_user_action() - elif team_number_validation() == False: + elif team_number_validation(team_number) == False: not_available() user_action = get_user_action() elif number_validation() == False: @@ -146,11 +143,11 @@ def team_number_validation(): #view a team team_number = defining_team_number() if number_validation() == True: - team_number == int(team_number) - if team_number_validation() == True: + team_number = int(team_number) + if team_number_validation(team_number) == True: print(team_dictionary[team_number]) user_action = get_user_action() - elif team_number_validation() == False: + elif team_number_validation(team_number) == False: not_available() user_action = get_user_action() elif number_validation() == False: @@ -160,11 +157,11 @@ def team_number_validation(): #remove a team team_name = defining_team_number() if number_validation() == True: - team_number == int(team_number) - if team_number_validation() == True: + team_number = int(team_number) + if team_number_validation(team_number) == True: team_dictionary.pop(team_number) user_action = get_user_action() - elif team_number_validation() == False: + elif team_number_validation(team_number) == False: not_available() user_action = get_user_action() elif number_validation() == False: @@ -174,11 +171,11 @@ def team_number_validation(): #search a team team_number = defining_team_number() if number_validation() == True: - team_number == int(team_number) - if team_number_validation() == True: + team_number = int(team_number) + if team_number_validation(team_number) == True: print(team_dictionary[team_number]) user_action = get_user_action() - elif team_number_validation() == False: + elif team_number_validation(team_number) == False: not_available() user_action = get_user_action() elif number_validation() == False: From 7678afb624c05036f05d9a36c40618468512e965 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 23 Oct 2019 20:28:53 -0700 Subject: [PATCH 18/25] write code --- ch_4_assign_emily_xia.py | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ch_4_assign_emily_xia.py diff --git a/ch_4_assign_emily_xia.py b/ch_4_assign_emily_xia.py new file mode 100644 index 0000000..12c92e2 --- /dev/null +++ b/ch_4_assign_emily_xia.py @@ -0,0 +1,65 @@ +from math import sqrt; +import math; +def number_validation(number): + return number.isdigit() + +class Point_2D: + x = 0; + y = 0; + distance = 0; + def __init__(self, x, y): + self.x = x + self.y = y + def distance(self): + return sqrt(math.pow(int(self.x), 2) + math.pow(int(self.y), 2)) + +x = input("What is your 2D x value?\n") +while number_validation(x) == False: + print("I'm sorry, please input an integer\n") + x = input("What is your 2D x value?\n") +y = input("What is your 2D y value?\n") +while number_validation(y) == False: + print("I'm sorry, please input an integer\n") + y = input("What is your 2D y value?\n") + +point_2D = Point_2D(x, y) +print("The distance of your two points from the origin " + str(point_2D.distance())) + +class Point_3D(Point_2D): + def __init__(self, x, y, z): + super().__init__(x, y) + self.z = z + def distance(self): + return 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() + +x = input("\nWhat is your 3D x value?\n") +while number_validation(x) == False: + print("I'm sorry, please input an integer\n") + x = input("What is your 3D x value?\n") +y = input("What is your 3D y value?\n") +while number_validation(y) == False: + print("I'm sorry, please input an integer\n") + y = input("What is your 3D y value?\n") +z = input("What is your 3D z value?\n") +while number_validation(z) == False: + print("I'm sorry, please input an integer\n") + z = input("What is your 3D z value?\n") + +point_3D = Point_3D(x, y, z) +print("The distance of your three points from the origin is " + str(point_3D.distance())) + +if point_2D.distance() > point_3D.distance(): + print("\nThe 2D point is farther from the origin than the 3D point\n") +elif point_2D.distance() < point_3D.distance(): + print("\nThe 3D point is farther from the origin than the 2D point\n") +elif point_2D.distance() == point_3D.distance(): + print("\nThe two points are the same distance from the origin\n") + +if point_2D.distance() > point_3D.distance_2D(): + print("The x and y cooridnate of the 2D point are farther than that of the 3D point\n") +elif point_2D.distance() < point_3D.distance_2D(): + print("The x and y cooridnate of the 3D point are farther than that of the 2D point\n") +elif point_2D.distance() == point_3D.distance_2D(): + print("The x and y cooridnates of the 2D and 3D points are of equal distance") \ No newline at end of file From fe5a080824ac8e8a5ac949bb972e1037be2c3aee Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 23 Oct 2019 20:31:21 -0700 Subject: [PATCH 19/25] remove ; from code --- ch_4_assign_emily_xia.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ch_4_assign_emily_xia.py b/ch_4_assign_emily_xia.py index 12c92e2..72248d8 100644 --- a/ch_4_assign_emily_xia.py +++ b/ch_4_assign_emily_xia.py @@ -1,12 +1,12 @@ -from math import sqrt; -import math; +from math import sqrt +import math def number_validation(number): return number.isdigit() class Point_2D: - x = 0; - y = 0; - distance = 0; + x = 0 + y = 0 + distance = 0 def __init__(self, x, y): self.x = x self.y = y From 75d28e7525a00696cb44b31fb6cff7ceb5f80611 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 30 Oct 2019 20:05:26 -0700 Subject: [PATCH 20/25] improve code based on comment --- ch_2_assign_emily_xia.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 75989a6..dd24891 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -47,7 +47,7 @@ modify_attribute = input("What is the attribute that you want to modify? \n") if modify_attribute in team_dictionary[modify_team]: new_attribute = input("What do you want the new "+modify_attribute+" to be? \n") - team_dictionary.update({modify_team:{modify_attribute:new_attribute}}) + team_dictionary[modify_team].update({modify_attribute:new_attribute}) print(team_dictionary[modify_team]) user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") elif modify_team not in team_dictionary[modify_team]: @@ -58,7 +58,7 @@ user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") elif user_action == "3": #viewing a team - view_team = int(input("What is the number of the team you want to view? \n ")) + view_team = input("What is the number of the team you want to view? \n ") if view_team in team_dictionary: print(team_dictionary[view_team]) elif view_team not in team_dictionary: @@ -67,16 +67,16 @@ elif user_action == "4": #removing a team print(team_dictionary) - remove_team = int(input("What is the number of the team you want to remove? \n ")) + remove_team = input("What is the number of the team you want to remove? \n ") if remove_team in team_dictionary: team_dictionary.pop(remove_team) print("Team" +remove_team+ "has been removed from the team dictionary!") elif remove_team not in team_dictionary: print("I'm sorry, the team you are looking for does not exist.") - user_action = input("""If you want to continue, press 4. \nIf you want to exit the "remove" function, press 0. \n """) + user_action = input("""If you want to continue, press 4. \nIf you want to exit the "remove" function, press 0.\n """) elif user_action == "5": #searching for a team - search_team = input("What is the number of the team you want to search for? \n") + search_team = input("What is the number or name of the team you want to search for?\n") if search_team in team_dictionary: print("Yes, the team you are looking for is in the team dictionary") else: @@ -89,11 +89,11 @@ if not result: print("""I'm sorry, but the team you are looking for is not in the team dictionary. Please make sure that your input is an integer.""") - user_action = input("""If you want to continue, press 5. \n If you want to exit the "search" function, press 0. \n """) + user_action = input("""If you want to continue, press 5. \n If you want to exit the "search" function, press 0.\n """) elif user_action == "6": #listing all teams print(team_dictionary) - user_action = input("""If you want to continue, press 6. \nIf you want to exit the "list" function, press 0. \n """) + user_action = input("""If you want to continue, press 6. \nIf you want to exit the "list" function, press 0.\n """) elif user_action not in ["0", "1", "2", "3", "4", "5", "6", "7"]: #returning to main menu if user_action is not a known value print("I'm sorry, could you please re-enter your command?") @@ -106,4 +106,4 @@ 6 list all teams 7 leave \n""") elif user_action == "7": - break + break \ No newline at end of file From c98f5d0f90c20868ce0f6c6785de2bf2bb375f5f Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 30 Oct 2019 20:07:25 -0700 Subject: [PATCH 21/25] improve code based on comments --- ch_3_assign_emily_xia.py | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/ch_3_assign_emily_xia.py b/ch_3_assign_emily_xia.py index 52e2535..3cabf10 100644 --- a/ch_3_assign_emily_xia.py +++ b/ch_3_assign_emily_xia.py @@ -1,9 +1,10 @@ team_dictionary={ 1678:{ + "Name":"Citrus Circuits", "Location":"Davis_CA", "Rookie_year":2005, "Competition_Status_2019":True, - "Names_of_Competions":{ + "Names_of_Competitions":{ "Central_Valley_Regional":"Fresno_CA", "Sacramento_Regional":"Davis_CA", "Aerospace_Valley_Regional":"Lancaster_CA", @@ -21,10 +22,11 @@ "Championship_Subdivision_Winner", "Entrepreneurship-Award"]}, 3132:{ + "Name":"Thunder Down Under", "Location":"Sydney_Australia", "Rookie_year":2010, "Competition_Status_2019":True, - "Names_of_Competions":{ + "Names_of_Competitions":{ "Southern_Cross_Regional":"Sydeny_Olympic_Park", "South_Pacific_Regional":"Sydeny_Olympic_Park", "Carver_Division":"Houston_TX", @@ -35,10 +37,11 @@ "Regional_Engineering_Inspiration", "Safety_Award"]}, 1902:{ + "Name":"Exploding Bacon", "Location":"Orlando_FL", "Rookie_year":2006, "Competition_Status-2019":True, - "Names_of_Competions":{ + "Names_of_Competitions":{ "Palmetto_Regional":"Myrtle_Beach", "Orlando_Regional":"Orlando_FL", "Newton_Division":"Houston_TX", @@ -49,19 +52,21 @@ "Entrepreneurship-Award", "Chairmans_Award_Finalist"]}, 5458:{ + "Name":"Digital Minds", "Location":"Woodland_CA", "Rookie_year":2015, "Competition_Status_2019":True, - "Names_of_Competions":{ + "Names_of_Competitions":{ "Central_Valley_Regional":"Fresno_CA", "Sacramento_Regional":"Davis_CA"}, "Competition_Awards":[ "None"]}, 6174:{ + "Name":"Kaprekar's Constants", "Location":"Winters_CA", "Rookie_year":2016, "Competition_Status_2019":True, - "Names_of_Competions":{ + "Names_of_Competitions":{ "Sacramento_Regional":"Davis_CA"}, "Competition_Awards":[ "None"]}} @@ -99,12 +104,14 @@ def team_number_validation(team): if number_validation() == True: team_number = int(team_number) if team_number_validation(team_number) == False: + Name = input("What is the name of your team?\n") Location = input("What is the location of your team? \n") Rookie_year = input("What is the rookie year of your team? \n") Competition_Status_2019 = input("What is the 2019 competition status of your team? \n") - Names_of_Competions = input("What are the names of the competitions of your team? \n") + Names_of_Competitions = input("What are the names of the competitions of your team? \n") Competition_Awards = input("What are the names of the competition awards of your team? \n") added_team_information = { + "Name":Name, "Location":Location, "Rookie_year":Rookie_year, "Competition_Status_2019": Competition_Status_2019, @@ -117,7 +124,7 @@ def team_number_validation(team): user_action = get_user_action() elif number_validation() == False: print("Your input is not an integer, please ensure that you input an integer") - team_number = defining_team_number() + user_action = get_user_action() elif user_action == 2: #modify a team team_number = defining_team_number() @@ -126,8 +133,8 @@ def team_number_validation(team): if team_number_validation(team_number) == True: modify_attribute = input("What is the attribute that you want to modify?\n") if modify_attribute in team_dictionary[team_number]: - new_attribute = input("What do you want the new " +modify_attribute+ "to be?\n") - team_dictionary.update({team_number:{modify_attribute:new_attribute}}) + new_attribute = input("What do you want the new " +modify_attribute+ " to be?\n") + team_dictionary[team_number].update({modify_attribute:new_attribute}) print(team_dictionary[team_number]) user_action = get_user_action() elif modify_attribute not in team_dictionary[team_number]: @@ -138,7 +145,7 @@ def team_number_validation(team): user_action = get_user_action() elif number_validation() == False: print("Your input is not an integer, please ensure that you input an integer") - team_number = defining_team_number() + user_action = get_user_action() elif user_action == 3: #view a team team_number = defining_team_number() @@ -152,24 +159,25 @@ def team_number_validation(team): user_action = get_user_action() elif number_validation() == False: print("Your input is not an integer, please ensure that you input an integer") - team_number = defining_team_number() + user_action = get_user_action() elif user_action == 4: #remove a team - team_name = defining_team_number() + team_number = defining_team_number() if number_validation() == True: team_number = int(team_number) if team_number_validation(team_number) == True: team_dictionary.pop(team_number) + print(team_dictionary) user_action = get_user_action() elif team_number_validation(team_number) == False: not_available() user_action = get_user_action() elif number_validation() == False: print("Your input is not an integer, please ensure that you input an integer") - team_number = defining_team_number() + user_action = get_user_action() elif user_action == 5: #search a team - team_number = defining_team_number() + team_number = input("Enter the number or name of your team\n") if number_validation() == True: team_number = int(team_number) if team_number_validation(team_number) == True: @@ -179,7 +187,14 @@ def team_number_validation(team): not_available() user_action = get_user_action() elif number_validation() == False: - print("Your input is not an integer, please ensure that you input an integer") + for key in team_dictionary: + if team_number == team_dictionary[key]["Name"]: + team_number = str(team_number) + print(team_dictionary[key]) + user_action = get_user_action() + else: + not_available() + user_action =get_user_action() elif user_action == 6: #list all teams for team_number, team_attributes in team_dictionary.items(): From 15e8f22ad696aefeda200f565112d8ab757b239e Mon Sep 17 00:00:00 2001 From: emxia18 Date: Wed, 6 Nov 2019 20:40:39 -0800 Subject: [PATCH 22/25] improve modify function --- ch_2_assign_emily_xia.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index dd24891..2b27838 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -50,6 +50,9 @@ team_dictionary[modify_team].update({modify_attribute:new_attribute}) print(team_dictionary[modify_team]) user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") + if modify_attribute == "number": + team_dictionary[new_attribute] = team_dictionary[modify_team] + team_dictionary.pop(modify_team) elif modify_team not in team_dictionary[modify_team]: print("I'm sorry, the team you want to modify is not in the dictionary.") user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") From 2ff39431cbd6c388eb84ea375cf638bc17f8bfdf Mon Sep 17 00:00:00 2001 From: emxia18 Date: Fri, 8 Nov 2019 00:02:16 -0800 Subject: [PATCH 23/25] add validation add validation for all categories when adding and modifying a team --- ch_2_assign_emily_xia.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 2b27838..41b5943 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -21,12 +21,26 @@ elif user_action == "1": #adding a team number = input("What is your team number? \n") + while number.isdigit() == False: + number = input("Your input is not an integer, please input an integer \n") name = input("What is the name of your team? \n") + while name.isdigit() == True: + name = input("Your input is not a string, please input a string\n") programming_language = input("What is the programming language of your team? \n") + while programming_language.isdigit() == True: + programming_language = input("Your input is not a string, please input a string\n") width = input("What is the width of your robot? \n") + while width.isdigit() == False: + width = input("Your input is not an integer, please input an integer \n") length = input("What is the length of your robot? \n") + while length.isdigit() == False: + length = input("Your input is not an integer, please input an integer \n") camera_vision_system = input("True or False, your robot has a camera vision system? \n") + while camera_vision_system.isdigit() == True: + camera_vision_system = input("Your input is not a boolean, please input a boolean\n") number_of_motors = input("How many motors does your robot have? \n") + while number_of_motors.isdigit() == False: + number_of_motors = input("Your input is not an integer, please input an integer \n") added_team_information = { "number": number, "name": name, @@ -47,6 +61,27 @@ modify_attribute = input("What is the attribute that you want to modify? \n") if modify_attribute in team_dictionary[modify_team]: new_attribute = input("What do you want the new "+modify_attribute+" to be? \n") + if modify_attribute == "number": + while new_attribute.isdigit() == False: + new_attribute = input("Your input is not an integer, please input a integer\n") + elif modify_attribute == "name": + while new_attribute.isdigit() == True: + new_attribute = input("Your input is not a string, please input a string\n") + elif modify_attribute == "programming_language": + while new_attribute.isdigit() == True: + new_attribute = input("Your input is not a string, please input a string\n") + elif modify_attribute == "width": + while new_attribute.isdigit() == False: + new_attribute = input("Your input is not an integer, please input a integer\n") + elif modify_attribute == "length": + while new_attribute.isdigit() == False: + new_attribute = input("Your input is not an integer, please input a integer\n") + elif modify_attribute == "camera_vision_system": + while new_attribute.isdigit() == True: + new_attribute = input("Your input is not a boolean, please input a boolean\n") + elif modify_attribute == "number_of_motors": + while new_attribute.isdigit() == False: + new_attribute = input("Your input is not an integer, please input a integer\n") team_dictionary[modify_team].update({modify_attribute:new_attribute}) print(team_dictionary[modify_team]) user_action = input("""If you want to continue, press 2. \nIf you want to exit the "modify" function, press 0. \n""") @@ -73,7 +108,7 @@ remove_team = input("What is the number of the team you want to remove? \n ") if remove_team in team_dictionary: team_dictionary.pop(remove_team) - print("Team" +remove_team+ "has been removed from the team dictionary!") + print("Team " +remove_team+ " has been removed from the team dictionary!") elif remove_team not in team_dictionary: print("I'm sorry, the team you are looking for does not exist.") user_action = input("""If you want to continue, press 4. \nIf you want to exit the "remove" function, press 0.\n """) From 8355718ab1a0531403de67ad4dd537a7e783b617 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Fri, 8 Nov 2019 21:59:48 -0800 Subject: [PATCH 24/25] add validation change camera_vision_system so that it will only accept "True" or "False" --- ch_2_assign_emily_xia.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py index 41b5943..28fa78d 100644 --- a/ch_2_assign_emily_xia.py +++ b/ch_2_assign_emily_xia.py @@ -36,8 +36,18 @@ while length.isdigit() == False: length = input("Your input is not an integer, please input an integer \n") camera_vision_system = input("True or False, your robot has a camera vision system? \n") - while camera_vision_system.isdigit() == True: - camera_vision_system = input("Your input is not a boolean, please input a boolean\n") + while True: + if camera_vision_system != "True": + if camera_vision_system != "False": + camera_vision_system = input("Your input is not a boolean, please input either 'True' or 'False' \n") + if camera_vision_system == "True": + break + elif camera_vision_system == "False": + break + else: + break + else: + break number_of_motors = input("How many motors does your robot have? \n") while number_of_motors.isdigit() == False: number_of_motors = input("Your input is not an integer, please input an integer \n") @@ -77,8 +87,18 @@ while new_attribute.isdigit() == False: new_attribute = input("Your input is not an integer, please input a integer\n") elif modify_attribute == "camera_vision_system": - while new_attribute.isdigit() == True: - new_attribute = input("Your input is not a boolean, please input a boolean\n") + while True: + if new_attribute != "True": + if new_attribute != "False": + new_attribute = input("Your input is not a boolean, please input either 'True' or 'False' \n") + if new_attribute == "True": + break + elif new_attribute == "False": + break + else: + break + else: + break elif modify_attribute == "number_of_motors": while new_attribute.isdigit() == False: new_attribute = input("Your input is not an integer, please input a integer\n") From 525ff9799b92d970c04079b68febf3c95272bf52 Mon Sep 17 00:00:00 2001 From: emxia18 Date: Sun, 10 Nov 2019 14:36:30 -0800 Subject: [PATCH 25/25] add validation added validation requiring an integer for Rookie_year and boolean for Competition_Status_2019 --- ch_3_assign_emily_xia.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/ch_3_assign_emily_xia.py b/ch_3_assign_emily_xia.py index 3cabf10..773ceae 100644 --- a/ch_3_assign_emily_xia.py +++ b/ch_3_assign_emily_xia.py @@ -84,6 +84,14 @@ def defining_team_number(): return input("Enter the number of your team \n") def get_user_action(): return int(input(main_menu)) +def isbool(input_variable): + while True: + if input_variable == "True": + return True + elif input_variable == "False": + return True + else: + return False def new_action(): return input() def not_available(): @@ -107,7 +115,11 @@ def team_number_validation(team): Name = input("What is the name of your team?\n") Location = input("What is the location of your team? \n") Rookie_year = input("What is the rookie year of your team? \n") + while Rookie_year.isdigit() == False: + Rookie_year = input("Your input is not an integer, please ensure that your input is an integer \n") Competition_Status_2019 = input("What is the 2019 competition status of your team? \n") + while isbool(Competition_Status_2019) == False: + Competition_Status_2019 = input("Your input is not a boolean, please input either 'True' or 'False' \n") Names_of_Competitions = input("What are the names of the competitions of your team? \n") Competition_Awards = input("What are the names of the competition awards of your team? \n") added_team_information = { @@ -134,9 +146,22 @@ def team_number_validation(team): modify_attribute = input("What is the attribute that you want to modify?\n") if modify_attribute in team_dictionary[team_number]: new_attribute = input("What do you want the new " +modify_attribute+ " to be?\n") - team_dictionary[team_number].update({modify_attribute:new_attribute}) - print(team_dictionary[team_number]) - user_action = get_user_action() + if modify_attribute == "Rookie_year": + while modify_attribute.isdigit() == False: + modify_attribute = input("Your input is not an integer, please ensure that you input an integer\n") + team_dictionary[team_number].update({modify_attribute:new_attribute}) + print(team_dictionary[team_number]) + user_action = get_user_action() + elif modify_attribute == "Competition_Status_2019": + while isbool(modify_attribute) == False: + modify_attribute = input("Your input is not a boolean, please input either 'True' or 'False' \n") + team_dictionary[team_number].update({modify_attribute:new_attribute}) + print(team_dictionary[team_number]) + user_action = get_user_action() + else: + team_dictionary[team_number].update({modify_attribute:new_attribute}) + print(team_dictionary[team_number]) + user_action = get_user_action() elif modify_attribute not in team_dictionary[team_number]: not_available() user_action = get_user_action()