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"]}} diff --git a/ch_1_assign_emily_xia.py b/ch_1_assign_emily_xia.py new file mode 100644 index 0000000..eb689c7 --- /dev/null +++ b/ch_1_assign_emily_xia.py @@ -0,0 +1,101 @@ +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"]}} +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 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') diff --git a/ch_2_assign_emily_xia.py b/ch_2_assign_emily_xia.py new file mode 100644 index 0000000..28fa78d --- /dev/null +++ b/ch_2_assign_emily_xia.py @@ -0,0 +1,167 @@ +team_dictionary = {} +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 """) +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 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") + 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 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") + 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") + 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 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") + 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""") + 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 = 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 = 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 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: + 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 \ No newline at end of file diff --git a/ch_3_assign_emily_xia.py b/ch_3_assign_emily_xia.py new file mode 100644 index 0000000..773ceae --- /dev/null +++ b/ch_3_assign_emily_xia.py @@ -0,0 +1,235 @@ +team_dictionary={ + 1678:{ + "Name":"Citrus Circuits", + "Location":"Davis_CA", + "Rookie_year":2005, + "Competition_Status_2019":True, + "Names_of_Competitions":{ + "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:{ + "Name":"Thunder Down Under", + "Location":"Sydney_Australia", + "Rookie_year":2010, + "Competition_Status_2019":True, + "Names_of_Competitions":{ + "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:{ + "Name":"Exploding Bacon", + "Location":"Orlando_FL", + "Rookie_year":2006, + "Competition_Status-2019":True, + "Names_of_Competitions":{ + "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:{ + "Name":"Digital Minds", + "Location":"Woodland_CA", + "Rookie_year":2015, + "Competition_Status_2019":True, + "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_Competitions":{ + "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 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(): + print("I'm sorry the information you are looking for is not available") +def number_validation(): + return team_number.isdigit() +def team_number_validation(team): + return team 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(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") + 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 = { + "Name":Name, + "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(team_number) == 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") + user_action = get_user_action() + 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(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") + 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() + 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") + user_action = get_user_action() + 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(team_number) == True: + print(team_dictionary[team_number]) + 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") + user_action = get_user_action() + elif user_action == 4: + #remove a team + 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") + user_action = get_user_action() + elif user_action == 5: + #search a team + 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: + print(team_dictionary[team_number]) + user_action = get_user_action() + elif team_number_validation(team_number) == False: + not_available() + user_action = get_user_action() + elif number_validation() == False: + 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(): + 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 diff --git a/ch_4_assign_emily_xia.py b/ch_4_assign_emily_xia.py new file mode 100644 index 0000000..72248d8 --- /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