diff --git a/ch_1_lesson_2_Harry_Jiang.py b/ch_1_lesson_2_Harry_Jiang.py new file mode 100644 index 0000000..7c5a0aa --- /dev/null +++ b/ch_1_lesson_2_Harry_Jiang.py @@ -0,0 +1,76 @@ +team_dict = { + 1: { + 'location' : "Pontact, Michigan, USA", + "rookie_year" : 1997 , + "2019_competition" : True, + "2019_competition_names" : [ + 'FIM Distric Center Line Event', + 'FIM District Troy Event' + ], + "2019_competition_location" : [ + 'Center Line, MI,USA', + 'Troy, MI, USA'], + "2019_awards" : False + }, + + + 20: { + 'location' : "Clifton Park, New Yourk, USA", + "rookie_year" : 1992 , + "2019_competition" : True, + "2019_competition_names" : [ + 'New York Tech Valley Regional', + 'Hudson Valley Regional', + 'Curie Division'], + "2019_competition_location" : ['Troy, NY, 12180, USA', + 'Suffern, NY, USA', + 'Detroit, MI, USA'], + "2019_awards" : False + }, + + 4 :{ + 'location' : "Van Nuys, California, USA", + "rookie_year" : 1997, + "2019_competition" : True, + "2019_competition_names" : [ + 'Los Angeles North Regional', + 'Los Angeles Regional', 'Wings Over Camarillo', + 'Batlleship Blast'], + "2019_competition_location" : [ + 'Valencia, CA, USA', + 'Los Angeles, CA, USA', + 'Camarillo, CA, USA', + 'San Pedro, CA, USA'], + "2019_awards" : False + }, + + 5 :{ + 'location' : "Melvindale, MI, USA", + "rookie_year" : 1998, + "2019_competition" : True, + "2019_competition_names" : ['Big Bang!'], + "2019_competition_location" : ['Taylor, MI, USA'], + "2019_awards" : False + }, + + 8 :{ + 'location' : 'Palo Alto, California, USA', + "rookie_year" : 1996, + "2019_compitition" : True, + "2019_competition_names" : [ + 'Del Mar Regional presented by Qualcomm', + 'Great Northern Regional', + 'Silicon Valley Regional'], + "2019_competition_location" : [ + 'Del Mar, CA, USA', + 'Grand Forks, ND, USA', + 'San Jose, CA, USA'], + "2019_awards" : False + }, + +} +print("Search a team") +team_dictionary = input("what team number: ") +print("What field(location, rookie_year, 2019_competition, 2019_competition_names, 2019_competition_location, 2019_award") +team_field = input("what field: ") +print(team_dict[int(team_dictionary)][team_field]) \ No newline at end of file diff --git a/ch_2_assign_Harry_Jiang.py b/ch_2_assign_Harry_Jiang.py new file mode 100644 index 0000000..df2125d --- /dev/null +++ b/ch_2_assign_Harry_Jiang.py @@ -0,0 +1,111 @@ +teams = {'teddy': {'number': '7', 'programming_language': '5', 'width': '5', 'length': '5', 'vision_system': 'yes', 'number_of_drivetrain_motors': '3'}, 'emily': {'number': '4', 'programming_language': 'c++', 'width': '3', 'length': '5', 'vision_system': 'no', 'number_of_drivetrain_motors': '9'}} +command = '' +while command != 'quit': + command = input ("What is your command(add a team, update a team, search a team, delete a team, list all teams, quit)") + #print(command); + if command == 'add a team' : + team_name = input ("What is team name? ") + print(team_name) + # Number, name, programming language, width, length, has camera vision system, number of drivetrain motors + number = input('number:') + if not number.isnumeric(): + print("your input for team number: "+ number + " is invalid") + else: + programming_language = input('progamming language: ') + #print(programming_language) + if programming_language.lower() not in ['java', 'python', 'c++']: + print("input is invalid") + isInputValid = False + else: + width = input('width:') + if not width.isnumeric(): + print("your input for width: "+ width +" is invalid") + else: + length = input('length:') + if not length.isnumeric(): + print("your input for length: "+ length +" is invalid") + else: + vision_system = input('has a camera vision system:') + if vision_system != 'yes' and vision_system != 'no': + print("your input for vision system: "+ vision_system +" is invalid") + else: + number_of_drivetrain_motors = input('number of drivetrain motors:') + team_info = {} + team_info.update(number = number) + team_info.update(programming_language = programming_language) + team_info.update(width = width) + team_info.update(length = length) + team_info.update(vision_system = vision_system) + team_info.update(number_of_drivetrain_motors = number_of_drivetrain_motors) + #print(team_info) + teams[team_name] = team_info + print('team ' + team_name + ' has created successfully.') + print(teams[team_name]) + if command == 'update a team': + print('update a team') + team_name = input('What team needs an update? ') + if team_name in teams.keys(): + print("number, programming_language, width, length, vision_system, number_of_drivetrain_motors") + field = input('What field needs and update: ') + value = input('value: ') + isInputValid = True + if field in ['number','width', 'length', 'number_of_drivetrain_motors']: + if not value.isnumeric(): + print('input is not valid') + isInputValid = False + elif field == "vision_system": + if value.lower() != 'yes' and value.lower() !='no': + print("input is invalid") + isInputValid = False + elif field == "programming_language": + if value.lower() not in ['java', 'python', 'c++']: + print("input is invalid") + isInputValid = False + else: + print("field you want to update is invalid") + isInputValid = False + + if isInputValid: + teams[team_name][field] = value + print("team updated successfully") + print(teams[team_name]) + + else: + print('team does not exist') + if command == 'search a team': + team_name_type = input('would you like to search by name or number? \n') + if team_name_type == "name": + team_name = input('What team? ') + if team_name in teams.keys(): + print("Yes, team is in dictionary") + pass + else: + print('team does not exist') + pass + + if team_name_type == "number": + team_number = input('what team number? ') + if team_number.isnumeric(): + isTeamNumberValid = False + for key, value in teams.items(): + #print(team_number) + #print(value["number"]) + if team_number == value["number"]: + isTeamNumberValid = True + break + if isTeamNumberValid: + print("Yes, team is in dicitionary") + else: + print("Team does not exist") + + if command == 'delete a team': + team_name = input('delete which team? ') + if team_name in teams.keys(): + print(teams.keys()) + teams.pop(team_name) + print(teams.keys()) + else: + print('team ' + team_name +' does not exist') + if command == 'list all teams': + print(teams) +print('end') \ No newline at end of file diff --git a/ch_3_assign_Harry_Jiang.py b/ch_3_assign_Harry_Jiang.py new file mode 100644 index 0000000..415b1fa --- /dev/null +++ b/ch_3_assign_Harry_Jiang.py @@ -0,0 +1,128 @@ +def add_a_team(): + team_name = input ("What is team name? ") + print(team_name) + # Number, name, programming language, width, length, has camera vision system, number of drivetrain motors + number = input('number:') + if not number.isnumeric(): + print("your input for team number: "+ number + " is invalid") + else: + programming_language = input('progamming language: ') + #print(programming_language) + if programming_language.lower() not in ['java', 'python', 'c++']: + print("input is invalid") + isInputValid = False + else: + width = input('width:') + if not width.isnumeric(): + print("your input for width: "+ width +" is invalid") + else: + length = input('length:') + if not length.isnumeric(): + print("your input for length: "+ length +" is invalid") + else: + vision_system = input('has a camera vision system:') + if vision_system != 'yes' and vision_system != 'no': + print("your input for vision system: "+ vision_system +" is invalid") + else: + number_of_drivetrain_motors = input('number of drivetrain motors:') + team_info = {} + team_info.update(number = number) + team_info.update(programming_language = programming_language) + team_info.update(width = width) + team_info.update(length = length) + team_info.update(vision_system = vision_system) + team_info.update(number_of_drivetrain_motors = number_of_drivetrain_motors) + #print(team_info) + teams[team_name] = team_info + print('team ' + team_name + ' has created successfully.') + print(teams[team_name]) +def update_a_team(): + print('update a team') + team_name = input('What team needs an update? ') + print(teams[team_name]) + if team_name in teams.keys(): + print("number, programming_language, width, length, vision_system, number_of_drivetrain_motors") + field = input('What field needs and update: ') + value = input('value: ') + isInputValid = True + if field in ['number','width', 'length', 'number_of_drivetrain_motors']: + if not value.isnumeric(): + print('input is not valid') + isInputValid = False + elif field == "vision_system": + if value.lower() != 'yes' and value.lower() !='no': + print("input is invalid") + isInputValid = False + elif field == "programming_language": + if value.lower() not in ['java', 'python', 'c++']: + print("input is invalid") + isInputValid = False + else: + print("field you want to update is invalid") + isInputValid = False + + + if isInputValid: + teams[team_name][field] = value + print("team updated successfully") + print(teams[team_name]) + + + else: + print('team does not exist') +def search_a_team(): + team_name_type = input('would you like to search by name or number? \n') + if team_name_type == "name": + team_name = input('What team? ') + if team_name in teams.keys(): + print("Yes, team is in dictionary") + pass + else: + print('team does not exist') + pass + + if team_name_type == "number": + team_number = input('what team number? ') + if team_number.isnumeric(): + isTeamNumberValid = False + for key, value in teams.items(): + #print(team_number) + #print(value["number"]) + if team_number == value["number"]: + isTeamNumberValid = True + break + if isTeamNumberValid: + print("Yes, team is in dicitionary") + else: + print("Team does not exist") +def delete_a_team(): + team_name = input('delete which team? ') + if team_name in teams.keys(): + print(teams.keys()) + teams.pop(team_name) + print(teams.keys()) + else: + print('team ' + team_name +' does not exist') +def list_all_teams(): + print(teams) +teams = {'teddy': {'number': '7', 'programming_language': '5', 'width': '5', 'length': '5', 'vision_system': 'yes', 'number_of_drivetrain_motors': '3'}, 'emily': {'number': '4', 'programming_language': 'c++', 'width': '3', 'length': '5', 'vision_system': 'no', 'number_of_drivetrain_motors': '9'}} +command = '' +while command != 'quit': + command = input ("What is your command(add a team, update a team, search a team, delete a team, list all teams, quit)") + #print(command); + if command == 'add a team' : + add_a_team() + + if command == 'update a team': + update_a_team() + + if command == 'search a team': + search_a_team() + + if command == 'delete a team': + delete_a_team() + + if command == 'list all teams': + list_all_teams() + +print('end') \ No newline at end of file diff --git a/ch_4_assign_Harry_Jiang.py b/ch_4_assign_Harry_Jiang.py new file mode 100644 index 0000000..48b44c7 --- /dev/null +++ b/ch_4_assign_Harry_Jiang.py @@ -0,0 +1,69 @@ +import math + +class Point: + x = 0 + y = 0 + distance = 0 + def __init__(self, x, y): + self.x = x + self.y = y + + #calculate distance + def calculateDistance(self): + return math.sqrt(self.x*self.x + self.y*self.y) + +class Point_3D(Point): + def __init__(self, x, y, z): + super().__init__(x, y) + self.z = z + + def calculateDistance(self): + return math.sqrt(self.x*self.x + self.y*self.y + self.z*self.z) + + + +#aPoint = Point(1,1) +#print(aPoint.calculateDistance()) +#aPoint = Point_3D(1, 1, 1) +#print(aPoint.calculateDistance()) +IsInputValid = False +while IsInputValid == False: + pointinput = input('please enter the value of two dimensional point. put a "," between values\n') + coordinate = pointinput.split(',') + if not len(coordinate) == 2: + print("your input is invalid") + else: + if not coordinate[0].isnumeric() or not coordinate[1].isnumeric(): + print("your input is incorrect") + IsInputValid = False + else: + aPoint = Point(float(coordinate[0]), float(coordinate[1])) + distance2D = aPoint.calculateDistance() + print(distance2D) + IsInputValid = True + +Is3dInputValid = False +while Is3dInputValid == False: + point3Dinput = input('please enter the value of the three dimensional point. put a "," between values\n') + coordinate3D = point3Dinput.split(',') + if not len(coordinate3D) == 3: + print("your input is invalid") + else: + if not coordinate3D[0].isnumeric() or not coordinate3D[1].isnumeric() or not coordinate3D[2].isnumeric: + print("your input is incorrect") + Is3dInputValid = False + else: + bPoint = Point_3D(float(coordinate3D[0]), float(coordinate3D[1]), float(coordinate3D[2])) + distance3D = bPoint.calculateDistance() + print(distance3D) + Is3dInputValid = True + +if distance2D > distance3D: + print('two dimensional point distance is larger') +elif distance3D == distance2D: + print('two dimensional point and three dimensional point distance are equal') +else: + print('three dimensional point distance is larger') + + +