From 356dd12873c5f91b98e428f99d2dada17f3d192a Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Tue, 17 Sep 2019 21:47:37 -0700 Subject: [PATCH 01/21] type file --- ch_1_lesson_adam_hutchings.py | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ch_1_lesson_adam_hutchings.py diff --git a/ch_1_lesson_adam_hutchings.py b/ch_1_lesson_adam_hutchings.py new file mode 100644 index 0000000..a318e54 --- /dev/null +++ b/ch_1_lesson_adam_hutchings.py @@ -0,0 +1,52 @@ +list_1111 = [ + 'Edgewater, Maryland',2003,True,['CHS District Bethesda MS Event sponsored by Bechtel', #Just tons of lists until line 23 + 'CHS District Owings Mills MD Event sponsored by Leidos','FIRST Chesapeake District Championship'], + ['Bethesda, Maryland','Owings Mills, Maryland','Fairfax, Virginia'], + ['Autonomous Award sponsored by Ford',"District Chairman's Award",'Team Spirit Award sponsored by FCA Foundation']] + +list_1678 = [ + 'Davis, California',2005,True, + ['Central Valley Regional','Sacramento Regional','Aerospace Valley Regional','Carver Division','Einstein Field', + 'RCC Qianjiang International Robotics Invitational'],['Fresno, California','Davis, California','Lancaster, California', + 'Houston, Texas','Hangzhou, China'],["Regional Chairman's Award",'Regional Winners',"FIRST Dean's List Finalist Award", + 'Industrial Design Award sponsored by General Motors','Excellence in Engineering Award sponsored by Delphi', + 'Championship Subdivision Winner','Entrepeneurship Award sponsored by Kleiner Perkins Caufield and Byers']] + +list_2222 = [ + 'Tacoma, Washington',2007,False,"Pacific Northwest Regional",'Portland, Oregon','No awards. Boo-hoo...'] + +list_3333 = [ + 'Julesburg, Colorado',2010,False,"Colorado Regional",'Denver, Colorado','Judges Award'] + +list_5555 = [ + 'Warren, Michigan',2015,True,['FIM District Center Line Event','FIM District Marysville Event'], + ['Center Line, Michigan','Marysville, Michigan'],"District Event Winner"] + +valid_input_1 = False #Whether a valid input has been submitted for a team +valid_input_2 = False #Whether a valid input has been submitted for a statistic + +statistics_dictionary = {'location':0, 'rookie_year':1, 'competed':2, 'competition_names':3, +'competition_locations':4, 'season_awards':5} + + +while valid_input_1 == False: #Until a valid input has been submitted for a team + team_selection = str(input("What team would you like to view statistics about? ")) #Which team do you want? + if team_selection == '1111' or '1678' or '2222' or '3333' or '5555': #Breaking the loop for a valid input + valid_input_1 = True +if team_selection == '1111': + team_selection = list_1111 +if team_selection == '1678': + team_selection = list_1678 +if team_selection == '2222': + team_selection = list_2222 +if team_selection == '3333': + team_selection = list_3333 +if team_selection == '5555': + team_selection = list_5555 + +while valid_input_2 == False: #Until a valid input has been submitted for a statistic + statistic_wanted = input("Which statistic would you like to find out? ") #Which statistic do you want? + if statistic_wanted == 'location' or 'rookie_year' or 'competed' or 'competition_names' or 'competition_locations' or 'season_awards': #Breaking the loop for a valid input + valid_input_2 = True #Breako el infinito el loopo + +print(team_selection[statistics_dictionary[statistic_wanted]]) #Print the list selected, and the element of said list From bc2815a9316f0722d5fc0e5c91acf104f82e619d Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Tue, 17 Sep 2019 21:54:58 -0700 Subject: [PATCH 02/21] type code, fix bugs --- ch_1_lesson_adam_hutchings_1.py | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ch_1_lesson_adam_hutchings_1.py diff --git a/ch_1_lesson_adam_hutchings_1.py b/ch_1_lesson_adam_hutchings_1.py new file mode 100644 index 0000000..a318e54 --- /dev/null +++ b/ch_1_lesson_adam_hutchings_1.py @@ -0,0 +1,52 @@ +list_1111 = [ + 'Edgewater, Maryland',2003,True,['CHS District Bethesda MS Event sponsored by Bechtel', #Just tons of lists until line 23 + 'CHS District Owings Mills MD Event sponsored by Leidos','FIRST Chesapeake District Championship'], + ['Bethesda, Maryland','Owings Mills, Maryland','Fairfax, Virginia'], + ['Autonomous Award sponsored by Ford',"District Chairman's Award",'Team Spirit Award sponsored by FCA Foundation']] + +list_1678 = [ + 'Davis, California',2005,True, + ['Central Valley Regional','Sacramento Regional','Aerospace Valley Regional','Carver Division','Einstein Field', + 'RCC Qianjiang International Robotics Invitational'],['Fresno, California','Davis, California','Lancaster, California', + 'Houston, Texas','Hangzhou, China'],["Regional Chairman's Award",'Regional Winners',"FIRST Dean's List Finalist Award", + 'Industrial Design Award sponsored by General Motors','Excellence in Engineering Award sponsored by Delphi', + 'Championship Subdivision Winner','Entrepeneurship Award sponsored by Kleiner Perkins Caufield and Byers']] + +list_2222 = [ + 'Tacoma, Washington',2007,False,"Pacific Northwest Regional",'Portland, Oregon','No awards. Boo-hoo...'] + +list_3333 = [ + 'Julesburg, Colorado',2010,False,"Colorado Regional",'Denver, Colorado','Judges Award'] + +list_5555 = [ + 'Warren, Michigan',2015,True,['FIM District Center Line Event','FIM District Marysville Event'], + ['Center Line, Michigan','Marysville, Michigan'],"District Event Winner"] + +valid_input_1 = False #Whether a valid input has been submitted for a team +valid_input_2 = False #Whether a valid input has been submitted for a statistic + +statistics_dictionary = {'location':0, 'rookie_year':1, 'competed':2, 'competition_names':3, +'competition_locations':4, 'season_awards':5} + + +while valid_input_1 == False: #Until a valid input has been submitted for a team + team_selection = str(input("What team would you like to view statistics about? ")) #Which team do you want? + if team_selection == '1111' or '1678' or '2222' or '3333' or '5555': #Breaking the loop for a valid input + valid_input_1 = True +if team_selection == '1111': + team_selection = list_1111 +if team_selection == '1678': + team_selection = list_1678 +if team_selection == '2222': + team_selection = list_2222 +if team_selection == '3333': + team_selection = list_3333 +if team_selection == '5555': + team_selection = list_5555 + +while valid_input_2 == False: #Until a valid input has been submitted for a statistic + statistic_wanted = input("Which statistic would you like to find out? ") #Which statistic do you want? + if statistic_wanted == 'location' or 'rookie_year' or 'competed' or 'competition_names' or 'competition_locations' or 'season_awards': #Breaking the loop for a valid input + valid_input_2 = True #Breako el infinito el loopo + +print(team_selection[statistics_dictionary[statistic_wanted]]) #Print the list selected, and the element of said list From bfa7499af40aa73d3a50a4a2f31ff06ea88fac17 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Thu, 3 Oct 2019 19:06:00 -0700 Subject: [PATCH 03/21] Fix many bugs, FINALLY finish code --- ch_2_assign_adam_hutchings.py | 232 ++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 ch_2_assign_adam_hutchings.py diff --git a/ch_2_assign_adam_hutchings.py b/ch_2_assign_adam_hutchings.py new file mode 100644 index 0000000..73377f0 --- /dev/null +++ b/ch_2_assign_adam_hutchings.py @@ -0,0 +1,232 @@ +master_dictionary = {} #Setting up the master el dictionario +input_list = ['menu', 'view', 'remove', 'search', 'modify'] +statistic_list = ['tm', 'n', 'pl', 'w', 'l', 'cv', 'dt'] +#Translating user inputs into functions + +def remove_function(): + while True: #Idiotproofing code + removal = input("Which team would you like to remove? This action cannot be undone!") + if ("statistics" + removal) in master_dictionary: + master_dictionary[removal] = {} + break + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove more, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def view_function(): + valid_input_6 = False #This, and all other such "shells", is safeproofing so the code doesn't die if the user enters an invalid input. + while valid_input_6 == False: + viewing_selection = input("Which team's statistics would you like to view? ") + if "statistics" + str(viewing_selection) in master_dictionary: + valid_input_6 = True + valid_input_7 = False + while valid_input_7 == False: + statistic_selection = input("""Which statistic would you like to view? Please type one of + tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), + cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). """) + if statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': + print (master_dictionary["statistics" + viewing_selection][statistic_selection]) + valid_input_7 = True + elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': + print("That hasn't been added yet. Try something else.") + valid_input_7 = True + else: + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def search_teams(): #Searching teams + valid_input_4 = False + while valid_input_4 == False: + team_search = input("What team would you like to search for?") + if team_search.isdigit() == True: #If the search is all digits + valid_input_4 = True + for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search + if search == ("statistics" + team_search): + print("A match has been found!") + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + else: + print("A match has not been found.") + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def add_team(): #How to add a new team + print("You are adding a new file. The first step is to name your team.") + valid_team_name = False + while valid_team_name == False: + team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team + if team_name.isdigit() == True: #Checking if a team name is all digits + valid_team_name = True #Breaking the infinite loop + master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team + for yeet in statistic_list: + master_dictionary["statistics" + str(team_name)][yeet] = '' + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def add_statistic(): #How to add a statistic for a team + team_name = '' #Setting variables empty + datapoint = '' + team_name_validity = False + while team_name_validity == False: + team_name = input("Please select a team whose information you would like to modify.") #Finding the team + if ("statistics" + str(team_name)) in master_dictionary: + team_name_validity = True + statistic_validity = False + while statistic_validity == False: + statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), + a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), + and the number of drivetrain motors on your robot (dt). Which one of these options would you like + to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. + if statistic_added in statistic_list: + statistic_validity = True + for statistic_name in statistic_list: #For all possible statistic names + if statistic_added == statistic_name: #If the statistic selected has been found: + datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. + master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def modification_function(): #Modifying data in this program. + valid_input_3 = False + while valid_input_3 == False: + adding_teams = input("Would you like to add a new team or a new statistic? Please type 'team' or 'statistic'. ") #Whether new team files are still being created + if adding_teams == 'team': #Getting other functions to run + add_team() + valid_input_3 = True + if adding_teams == 'statistic' and master_dictionary != {}: #Checking if there are any teams for statistics to be added to + add_statistic() + valid_input_3 = True + +def menu_function(): + if master_dictionary == {}: + valid_input = False + while valid_input == False: + first_input = input("You don't seem to have any data. Enter 'yes' to add some. ") + if first_input == 'yes': + modification_function() + valid_input = True + else: #If information has already been saved. + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'view' to view more, + 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +menu_function() \ No newline at end of file From 6327cbe7de53dfa88105838846f511725121a1b6 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 16 Oct 2019 16:55:22 -0700 Subject: [PATCH 04/21] Not able to fix code, ask later --- ch_3_lesson_adam_hutchings.py | 232 ++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 ch_3_lesson_adam_hutchings.py diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py new file mode 100644 index 0000000..e27235a --- /dev/null +++ b/ch_3_lesson_adam_hutchings.py @@ -0,0 +1,232 @@ +master_dictionary = {} #Setting up the master el dictionario +input_list = ['menu', 'view', 'remove', 'search', 'modify'] +statistic_list = ['tm', 'n', 'pl', 'w', 'l', 'cv', 'dt'] +#Translating user inputs into functions + +def remove_function(): + while True: #Idiotproofing code + removal = input("Which team would you like to remove? This action cannot be undone!") + if ("statistics" + removal) in master_dictionary: + master_dictionary[removal] = {} + break + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove more, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def view_function(): + valid_input_6 = False #This, and all other such "shells", is safeproofing so the code doesn't die if the user enters an invalid input. + while valid_input_6 == False: + viewing_selection = input("Which team's statistics would you like to view? ") + if "statistics" + str(viewing_selection) in master_dictionary: + valid_input_6 = True + valid_input_7 = False + while valid_input_7 == False: + statistic_selection = input("""Which statistic would you like to view? Please type one of + tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), + cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). """) + if statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': + print (master_dictionary["statistics" + viewing_selection][statistic_selection]) + valid_input_7 = True + elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': + print("That hasn't been added yet. Try something else.") + valid_input_7 = True + else: + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def search_teams(): #Searching teams + valid_input_4 = False + while valid_input_4 == False: + team_search = input("What team would you like to search for?") + if team_search.isdigit() == True: #If the search is all digits + valid_input_4 = True + for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search + if search == ("statistics" + team_search): + print("A match has been found!") + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + else: + print("A match has not been found.") + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def add_team(): #How to add a new team + print("You are adding a new file. The first step is to name your team.") + valid_team_name = False + while valid_team_name == False: + team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team + if team_name.isdigit() == True: #Checking if a team name is all digits + valid_team_name = True #Breaking the infinite loop + master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team + for yeet in statistic_list: + master_dictionary["statistics" + str(team_name)][yeet] = '' + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def add_statistic(): #How to add a statistic for a team + team_name = '' #Setting variables empty + datapoint = '' + team_name_validity = False + while team_name_validity == False: + team_name = input("Please select a team whose information you would like to modify.") #Finding the team + if ("statistics" + str(team_name)) in master_dictionary: + team_name_validity = True + statistic_validity = False + while statistic_validity == False: + statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), + a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), + and the number of drivetrain motors on your robot (dt). Which one of these options would you like + to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. + if statistic_added in statistic_list: + statistic_validity = True + for statistic_name in statistic_list: #For all possible statistic names + if statistic_added == statistic_name: #If the statistic selected has been found: + datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. + master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +def modification_function(): #Modifying data in this program. + valid_input_3 = False + while valid_input_3 == False: + adding_teams = input("Would you like to add a new team or a new statistic? Please type 'team' or 'statistic'. ") #Whether new team files are still being created + if adding_teams == 'team': #Getting other functions to run + add_team() + valid_input_3 = True + if adding_teams == 'statistic' and master_dictionary != {}: #Checking if there are any teams for statistics to be added to + add_statistic() + valid_input_3 = True + +def menu_function(): + if master_dictionary == {}: + valid_input = False + while valid_input == False: + first_input = input("You don't seem to have any data. Enter 'yes' to add some. ") + if first_input == 'yes': + modification_function() + valid_input = True + else: #If information has already been saved. + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'view' to view more, + 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + +menu_function() \ No newline at end of file From 90d831ac68c7a06b0af225045058415daad5d795 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 16 Oct 2019 20:19:25 -0700 Subject: [PATCH 05/21] shorten code --- ch_3_lesson_adam_hutchings.py | 181 +++++++--------------------------- 1 file changed, 34 insertions(+), 147 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index e27235a..c7e86b1 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -13,112 +13,39 @@ def remove_function(): while valid_input_5 == False: menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, 'remove' to remove more, 'search' to search the teams, or 'modify' to modify the information.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() def view_function(): - valid_input_6 = False #This, and all other such "shells", is safeproofing so the code doesn't die if the user enters an invalid input. - while valid_input_6 == False: + while True: viewing_selection = input("Which team's statistics would you like to view? ") if "statistics" + str(viewing_selection) in master_dictionary: - valid_input_6 = True - valid_input_7 = False - while valid_input_7 == False: + break; + while True: statistic_selection = input("""Which statistic would you like to view? Please type one of tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). """) if statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': print (master_dictionary["statistics" + viewing_selection][statistic_selection]) - valid_input_7 = True + break; elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': print("That hasn't been added yet. Try something else.") - valid_input_7 = True - else: - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information.""") - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + break; def search_teams(): #Searching teams - valid_input_4 = False - while valid_input_4 == False: + while True: team_search = input("What team would you like to search for?") if team_search.isdigit() == True: #If the search is all digits - valid_input_4 = True + break; for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search if search == ("statistics" + team_search): print("A match has been found!") - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + else: + print("Oops, that isn't a team. ") else: print("A match has not been found.") valid_input_5 = False while valid_input_5 == False: menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() def add_team(): #How to add a new team print("You are adding a new file. The first step is to name your team.") @@ -134,74 +61,35 @@ def add_team(): #How to add a new team while valid_input_5 == False: menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() def add_statistic(): #How to add a statistic for a team team_name = '' #Setting variables empty datapoint = '' - team_name_validity = False - while team_name_validity == False: + while True: team_name = input("Please select a team whose information you would like to modify.") #Finding the team if ("statistics" + str(team_name)) in master_dictionary: - team_name_validity = True - statistic_validity = False - while statistic_validity == False: + break; + while True: statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), and the number of drivetrain motors on your robot (dt). Which one of these options would you like to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. - if statistic_added in statistic_list: - statistic_validity = True + if statistic_added in statistic_list: + break; for statistic_name in statistic_list: #For all possible statistic names if statistic_added == statistic_name: #If the statistic selected has been found: datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() def modification_function(): #Modifying data in this program. - valid_input_3 = False - while valid_input_3 == False: + while True: adding_teams = input("Would you like to add a new team or a new statistic? Please type 'team' or 'statistic'. ") #Whether new team files are still being created if adding_teams == 'team': #Getting other functions to run add_team() - valid_input_3 = True + break; if adding_teams == 'statistic' and master_dictionary != {}: #Checking if there are any teams for statistics to be added to add_statistic() - valid_input_3 = True + break; def menu_function(): if master_dictionary == {}: @@ -211,22 +99,21 @@ def menu_function(): if first_input == 'yes': modification_function() valid_input = True - else: #If information has already been saved. - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'view' to view more, - 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information.""") - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() -menu_function() \ No newline at end of file +while True: + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'view' to view, + 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information. """) + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() \ No newline at end of file From ab7134e45a96786dd09aabaa01ce8476fa1cae49 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Thu, 24 Oct 2019 20:00:32 -0700 Subject: [PATCH 06/21] learn classes, fix bugs --- ch_4_assign_Adam_hutchings.py | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ch_4_assign_Adam_hutchings.py diff --git a/ch_4_assign_Adam_hutchings.py b/ch_4_assign_Adam_hutchings.py new file mode 100644 index 0000000..323b446 --- /dev/null +++ b/ch_4_assign_Adam_hutchings.py @@ -0,0 +1,52 @@ +import math #For mathy stuff +class Point(): + def __init__(self, x_coord, y_coord): + self.x_coord = x_coord + self.y_coord = y_coord + + def distance(self): + return math.sqrt((float(self.x_coord) ** 2) + (float(self.y_coord) ** 2)) #Pythagorean calculation + +class Point_3D(Point): + def __init__(self, x_coord, y_coord ,z_coord): + super().__init__(x_coord,y_coord) + self.z_coord = z_coord + + def distance(self): #For 3D distance + return math.sqrt((super().distance()**2) + (float(self.z_coord)**2)) + +def distance_counter(user_x_1,user_y_1,user_x_2,user_y_2,user_z): + hypotenuse_2D = Point(user_x_1,user_y_1).distance() #So I can use it more efficiently later. + hypotenuse_3D = Point_3D(user_x_2,user_y_2,user_z).distance() #So I can use it more efficiently later. + print("Your first point is " + str(hypotenuse_2D) + '.') + print("Your second point is " + str(hypotenuse_3D)+'.') + + if hypotenuse_3D > hypotenuse_2D: + print("Your second point was further away. ") + elif hypotenuse_3D == hypotenuse_2D: + print("Your points tied. ") + else: + print("Your first point was further away. ") + +def is_float(user_input): + for character in user_input: + if character not in '0123456789.': + return False + if user_input is '': + return False + elif user_input.split().count(".") > 1: + return False + return True + +while True: + user_x_1 = input("What would you like your first 2D variable to be? ") + user_x_2 = input("What would you like your second 2D variable to be? ") + user_y_1 = input("What would you like your first 3D variable to be? ") + user_y_2 = input("What would you like your second 3D variable to be? ") + user_z = input("What would you like your third 3D variable to be? ") + + if is_float(str(user_x_1)) and is_float(str(user_x_2)) and is_float(str(user_y_1)) and is_float(str(user_y_2)) and is_float(str(user_z)) == True: + break; + else: + print("Uh-oh, you messed up! ") +distance_counter(user_x_1, user_x_2, user_y_1, user_y_2, user_z) \ No newline at end of file From 0838b43ba061aa4f0a76eb1a5dc84c3bbda21d8c Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Thu, 24 Oct 2019 20:21:12 -0700 Subject: [PATCH 07/21] Commit ch 2 and ch3 --- ch_2_assign_adam_hutchings.py | 424 +++++++++++++++++----------------- 1 file changed, 212 insertions(+), 212 deletions(-) diff --git a/ch_2_assign_adam_hutchings.py b/ch_2_assign_adam_hutchings.py index 73377f0..e27235a 100644 --- a/ch_2_assign_adam_hutchings.py +++ b/ch_2_assign_adam_hutchings.py @@ -4,229 +4,229 @@ #Translating user inputs into functions def remove_function(): - while True: #Idiotproofing code - removal = input("Which team would you like to remove? This action cannot be undone!") - if ("statistics" + removal) in master_dictionary: - master_dictionary[removal] = {} - break - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove more, 'search' to search the teams, or 'modify' to modify the information.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + while True: #Idiotproofing code + removal = input("Which team would you like to remove? This action cannot be undone!") + if ("statistics" + removal) in master_dictionary: + master_dictionary[removal] = {} + break + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove more, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() def view_function(): - valid_input_6 = False #This, and all other such "shells", is safeproofing so the code doesn't die if the user enters an invalid input. - while valid_input_6 == False: - viewing_selection = input("Which team's statistics would you like to view? ") - if "statistics" + str(viewing_selection) in master_dictionary: - valid_input_6 = True - valid_input_7 = False - while valid_input_7 == False: - statistic_selection = input("""Which statistic would you like to view? Please type one of - tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), - cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). """) - if statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': - print (master_dictionary["statistics" + viewing_selection][statistic_selection]) - valid_input_7 = True - elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': - print("That hasn't been added yet. Try something else.") - valid_input_7 = True - else: - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information.""") - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + valid_input_6 = False #This, and all other such "shells", is safeproofing so the code doesn't die if the user enters an invalid input. + while valid_input_6 == False: + viewing_selection = input("Which team's statistics would you like to view? ") + if "statistics" + str(viewing_selection) in master_dictionary: + valid_input_6 = True + valid_input_7 = False + while valid_input_7 == False: + statistic_selection = input("""Which statistic would you like to view? Please type one of + tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), + cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). """) + if statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': + print (master_dictionary["statistics" + viewing_selection][statistic_selection]) + valid_input_7 = True + elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': + print("That hasn't been added yet. Try something else.") + valid_input_7 = True + else: + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() def search_teams(): #Searching teams - valid_input_4 = False - while valid_input_4 == False: - team_search = input("What team would you like to search for?") - if team_search.isdigit() == True: #If the search is all digits - valid_input_4 = True - for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search - if search == ("statistics" + team_search): - print("A match has been found!") - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() - else: - print("A match has not been found.") - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + valid_input_4 = False + while valid_input_4 == False: + team_search = input("What team would you like to search for?") + if team_search.isdigit() == True: #If the search is all digits + valid_input_4 = True + for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search + if search == ("statistics" + team_search): + print("A match has been found!") + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() + else: + print("A match has not been found.") + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() def add_team(): #How to add a new team - print("You are adding a new file. The first step is to name your team.") - valid_team_name = False - while valid_team_name == False: - team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team - if team_name.isdigit() == True: #Checking if a team name is all digits - valid_team_name = True #Breaking the infinite loop - master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team - for yeet in statistic_list: - master_dictionary["statistics" + str(team_name)][yeet] = '' - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + print("You are adding a new file. The first step is to name your team.") + valid_team_name = False + while valid_team_name == False: + team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team + if team_name.isdigit() == True: #Checking if a team name is all digits + valid_team_name = True #Breaking the infinite loop + master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team + for yeet in statistic_list: + master_dictionary["statistics" + str(team_name)][yeet] = '' + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() def add_statistic(): #How to add a statistic for a team - team_name = '' #Setting variables empty - datapoint = '' - team_name_validity = False - while team_name_validity == False: - team_name = input("Please select a team whose information you would like to modify.") #Finding the team - if ("statistics" + str(team_name)) in master_dictionary: - team_name_validity = True - statistic_validity = False - while statistic_validity == False: - statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), - a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), - and the number of drivetrain motors on your robot (dt). Which one of these options would you like - to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. - if statistic_added in statistic_list: - statistic_validity = True - for statistic_name in statistic_list: #For all possible statistic names - if statistic_added == statistic_name: #If the statistic selected has been found: - datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. - master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") - if menu_selection in input_list: - if menu_selection == 'menu': - valid_input_5 = True - menu_function() - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + team_name = '' #Setting variables empty + datapoint = '' + team_name_validity = False + while team_name_validity == False: + team_name = input("Please select a team whose information you would like to modify.") #Finding the team + if ("statistics" + str(team_name)) in master_dictionary: + team_name_validity = True + statistic_validity = False + while statistic_validity == False: + statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), + a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), + and the number of drivetrain motors on your robot (dt). Which one of these options would you like + to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. + if statistic_added in statistic_list: + statistic_validity = True + for statistic_name in statistic_list: #For all possible statistic names + if statistic_added == statistic_name: #If the statistic selected has been found: + datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. + master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, + 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + if menu_selection in input_list: + if menu_selection == 'menu': + valid_input_5 = True + menu_function() + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() def modification_function(): #Modifying data in this program. - valid_input_3 = False - while valid_input_3 == False: - adding_teams = input("Would you like to add a new team or a new statistic? Please type 'team' or 'statistic'. ") #Whether new team files are still being created - if adding_teams == 'team': #Getting other functions to run - add_team() - valid_input_3 = True - if adding_teams == 'statistic' and master_dictionary != {}: #Checking if there are any teams for statistics to be added to - add_statistic() - valid_input_3 = True + valid_input_3 = False + while valid_input_3 == False: + adding_teams = input("Would you like to add a new team or a new statistic? Please type 'team' or 'statistic'. ") #Whether new team files are still being created + if adding_teams == 'team': #Getting other functions to run + add_team() + valid_input_3 = True + if adding_teams == 'statistic' and master_dictionary != {}: #Checking if there are any teams for statistics to be added to + add_statistic() + valid_input_3 = True def menu_function(): - if master_dictionary == {}: - valid_input = False - while valid_input == False: - first_input = input("You don't seem to have any data. Enter 'yes' to add some. ") - if first_input == 'yes': - modification_function() - valid_input = True - else: #If information has already been saved. - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'view' to view more, - 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information.""") - if menu_selection == 'view': - valid_input_5 = True - view_function() - if menu_selection == 'remove': - valid_input_5 = True - remove_function() - if menu_selection == 'search': - valid_input_5 = True - search_teams() - if menu_selection == 'modify': - valid_input_5 = True - modification_function() + if master_dictionary == {}: + valid_input = False + while valid_input == False: + first_input = input("You don't seem to have any data. Enter 'yes' to add some. ") + if first_input == 'yes': + modification_function() + valid_input = True + else: #If information has already been saved. + valid_input_5 = False + while valid_input_5 == False: + menu_selection = input("""Type 'view' to view more, + 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information.""") + if menu_selection == 'view': + valid_input_5 = True + view_function() + if menu_selection == 'remove': + valid_input_5 = True + remove_function() + if menu_selection == 'search': + valid_input_5 = True + search_teams() + if menu_selection == 'modify': + valid_input_5 = True + modification_function() menu_function() \ No newline at end of file From 6cde0b569354bd4fb35925291fd81fa37af84b55 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 30 Oct 2019 19:58:56 -0700 Subject: [PATCH 08/21] change to dictionary --- new_chapter_1_adam_hutchings.py | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 new_chapter_1_adam_hutchings.py diff --git a/new_chapter_1_adam_hutchings.py b/new_chapter_1_adam_hutchings.py new file mode 100644 index 0000000..d3206d5 --- /dev/null +++ b/new_chapter_1_adam_hutchings.py @@ -0,0 +1,50 @@ +master_dict = { +'dict_1111':{ + 'place':'Edgewater, Maryland', + 'year':2003, + 'active':True, + 'competitions':{'CHS District Bethesda MS Event sponsored by Bechtel', + 'CHS District Owings Mills MD Event sponsored by Leidos','FIRST Chesapeake District Championship'}, + 'locations':{'Bethesda, Maryland','Owings Mills, Maryland','Fairfax, Virginia'}, + 'awards':{'Autonomous Award sponsored by Ford',"District Chairman's Award",'Team Spirit Award sponsored by FCA Foundation'} + }, +'dict_1678':{ + 'place':'Davis, California', + 'year':2005, + 'active':True, + 'competitions':{'Central Valley Regional','Sacramento Regional','Aerospace Valley Regional','Carver Division','Einstein Field', + 'RCC Qianjiang International Robotics Invitational'}, + 'locations':{'Fresno, California','Davis, California','Lancaster, California', + 'Houston, Texas','Hangzhou, China'}, + 'awards':{"Regional Chairman's Award",'Regional Winners',"FIRST Dean's List Finalist Award", + 'Industrial Design Award sponsored by General Motors','Excellence in Engineering Award sponsored by Delphi', + 'Championship Subdivision Winner','Entrepeneurship Award sponsored by Kleiner Perkins Caufield and Byers'} +}, +'dict_2222':{ + 'place':'Tacoma, Washington', + 'year':2007, + 'active':False, + 'competitions':"Pacific Northwest Regional", + 'locations':'Portland, Oregon', + 'awards':'No awards. Boo-hoo...' +}, +'dict_3333':{ + 'place':'Julesburg, Colorado', + 'year':2010, + 'active':False, + 'competitions':"Colorado Regional", + 'locations':'Denver, Colorado', + 'awards':'Judges Award' +}, +'dict_5555':{ + 'place':'Warren, Michigan', + 'year':2015, + 'active':True, + 'competitions':{'FIM District Center Line Event','FIM District Marysville Event'}, + 'locations':{'Center Line, Michigan','Marysville, Michigan'}, + 'awards':"District Event Winner" +} +} +team = 'dict_' + input("Which team? ") +statistic = input("Which statistic? ") +print((master_dict[team])[statistic]) \ No newline at end of file From 4221a90ddd8fbe5954fe3a107d81c22ff8da2bce Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 30 Oct 2019 20:33:53 -0700 Subject: [PATCH 09/21] write code, use classes --- ch_4_assign_Adam_hutchings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ch_4_assign_Adam_hutchings.py b/ch_4_assign_Adam_hutchings.py index 323b446..ffae3b7 100644 --- a/ch_4_assign_Adam_hutchings.py +++ b/ch_4_assign_Adam_hutchings.py @@ -4,10 +4,10 @@ def __init__(self, x_coord, y_coord): self.x_coord = x_coord self.y_coord = y_coord - def distance(self): + def distance(self): #Distance return math.sqrt((float(self.x_coord) ** 2) + (float(self.y_coord) ** 2)) #Pythagorean calculation -class Point_3D(Point): +class Point_3D(Point): #Defining it for 3D def __init__(self, x_coord, y_coord ,z_coord): super().__init__(x_coord,y_coord) self.z_coord = z_coord @@ -28,7 +28,7 @@ def distance_counter(user_x_1,user_y_1,user_x_2,user_y_2,user_z): else: print("Your first point was further away. ") -def is_float(user_input): +def is_float(user_input): #Idiotproofing! for character in user_input: if character not in '0123456789.': return False From ac592087082f8cc62e91f9dc016b8afacadc2bce Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 6 Nov 2019 15:49:09 -0800 Subject: [PATCH 10/21] edit add function. --- ch_3_lesson_adam_hutchings.py | 55 +++++++++++++++-------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index c7e86b1..3fba9e9 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -8,11 +8,7 @@ def remove_function(): removal = input("Which team would you like to remove? This action cannot be undone!") if ("statistics" + removal) in master_dictionary: master_dictionary[removal] = {} - break - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove more, 'search' to search the teams, or 'modify' to modify the information.""") + break; def view_function(): while True: @@ -32,35 +28,30 @@ def view_function(): def search_teams(): #Searching teams while True: - team_search = input("What team would you like to search for?") - if team_search.isdigit() == True: #If the search is all digits + team_search = input("What team would you like to search for? ") + if team_search.isdigit() == False: #If the search is all digits + print("Oops, enter a valid input!") + continue; + else: break; - for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search - if search == ("statistics" + team_search): - print("A match has been found!") - else: - print("Oops, that isn't a team. ") - else: - print("A match has not been found.") - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams again, or 'modify' to modify the information.""") + for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search + if search == ("statistics" + team_search): + return ("A match has been found!") + break; + return ("No matches were found.") def add_team(): #How to add a new team - print("You are adding a new file. The first step is to name your team.") - valid_team_name = False - while valid_team_name == False: - team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team - if team_name.isdigit() == True: #Checking if a team name is all digits - valid_team_name = True #Breaking the infinite loop - master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team - for yeet in statistic_list: - master_dictionary["statistics" + str(team_name)][yeet] = '' - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'menu' to go back to the main menu, 'view' to view more, - 'remove' to remove data, 'search' to search the teams, or 'modify' to modify the information again.""") + print("You are adding a new file. The first step is to name your team.") + while True: + team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team + if team_name.isdigit() == False: #Checking if a team name is all digits + print("Valid input, please!") + continue; + else: + master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team + for yeet in statistic_list: + master_dictionary["statistics" + str(team_name)][yeet] = '' + break; def add_statistic(): #How to add a statistic for a team team_name = '' #Setting variables empty @@ -113,7 +104,7 @@ def menu_function(): remove_function() if menu_selection == 'search': valid_input_5 = True - search_teams() + print(search_teams()) if menu_selection == 'modify': valid_input_5 = True modification_function() \ No newline at end of file From f8f4f2aef7a2b7d0d960d56fe0eb70aaaeef94d2 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 6 Nov 2019 19:03:07 -0800 Subject: [PATCH 11/21] fix 'add' and 'statistic' --- ch_3_lesson_adam_hutchings.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index 3fba9e9..6fc7162 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -72,16 +72,6 @@ def add_statistic(): #How to add a statistic for a team datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint -def modification_function(): #Modifying data in this program. - while True: - adding_teams = input("Would you like to add a new team or a new statistic? Please type 'team' or 'statistic'. ") #Whether new team files are still being created - if adding_teams == 'team': #Getting other functions to run - add_team() - break; - if adding_teams == 'statistic' and master_dictionary != {}: #Checking if there are any teams for statistics to be added to - add_statistic() - break; - def menu_function(): if master_dictionary == {}: valid_input = False @@ -95,16 +85,24 @@ def menu_function(): valid_input_5 = False while valid_input_5 == False: menu_selection = input("""Type 'view' to view, - 'remove' to remove, 'search' to search the teams, or 'modify' to modify the information. """) + 'remove' to remove, 'search' to search the teams, 'add' to add a team, or + 'statistic' to add a statistic to a team's file. """) if menu_selection == 'view': valid_input_5 = True view_function() - if menu_selection == 'remove': + elif menu_selection == 'remove': valid_input_5 = True remove_function() - if menu_selection == 'search': + elif menu_selection == 'search': valid_input_5 = True print(search_teams()) - if menu_selection == 'modify': + elif menu_selection == 'add': valid_input_5 = True - modification_function() \ No newline at end of file + add_team() + elif menu_selection == 'statistic': + if master_dictionary != {}: + valid_input_5 = True + add_statistic() + else: + print("You don't have any teams! Darn it!") + continue; \ No newline at end of file From 81257d039961df1204e084d57e279a86cd5fb9ea Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Sat, 9 Nov 2019 20:01:17 -0800 Subject: [PATCH 12/21] Delete semicolons, add menu quit option. --- ch_3_lesson_adam_hutchings.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index 6fc7162..5197519 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -8,13 +8,13 @@ def remove_function(): removal = input("Which team would you like to remove? This action cannot be undone!") if ("statistics" + removal) in master_dictionary: master_dictionary[removal] = {} - break; + break def view_function(): while True: viewing_selection = input("Which team's statistics would you like to view? ") if "statistics" + str(viewing_selection) in master_dictionary: - break; + break while True: statistic_selection = input("""Which statistic would you like to view? Please type one of tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), @@ -24,20 +24,20 @@ def view_function(): break; elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': print("That hasn't been added yet. Try something else.") - break; + break def search_teams(): #Searching teams while True: team_search = input("What team would you like to search for? ") if team_search.isdigit() == False: #If the search is all digits print("Oops, enter a valid input!") - continue; + continue else: - break; + break for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search if search == ("statistics" + team_search): return ("A match has been found!") - break; + break return ("No matches were found.") def add_team(): #How to add a new team @@ -46,12 +46,12 @@ def add_team(): #How to add a new team team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team if team_name.isdigit() == False: #Checking if a team name is all digits print("Valid input, please!") - continue; + continue else: master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team for yeet in statistic_list: master_dictionary["statistics" + str(team_name)][yeet] = '' - break; + break def add_statistic(): #How to add a statistic for a team team_name = '' #Setting variables empty @@ -59,14 +59,14 @@ def add_statistic(): #How to add a statistic for a team while True: team_name = input("Please select a team whose information you would like to modify.") #Finding the team if ("statistics" + str(team_name)) in master_dictionary: - break; + break while True: statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), and the number of drivetrain motors on your robot (dt). Which one of these options would you like to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. if statistic_added in statistic_list: - break; + break for statistic_name in statistic_list: #For all possible statistic names if statistic_added == statistic_name: #If the statistic selected has been found: datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. @@ -86,7 +86,8 @@ def menu_function(): while valid_input_5 == False: menu_selection = input("""Type 'view' to view, 'remove' to remove, 'search' to search the teams, 'add' to add a team, or - 'statistic' to add a statistic to a team's file. """) + 'statistic' to add a statistic to a team's file. + Or type 'stop' to end this program. """) if menu_selection == 'view': valid_input_5 = True view_function() @@ -105,4 +106,9 @@ def menu_function(): add_statistic() else: print("You don't have any teams! Darn it!") - continue; \ No newline at end of file + continue + elif menu_selection == 'stop': + break + else: + print('Enter a valid input! ') + continue \ No newline at end of file From 627e31ffa24710c9c30d2e1d19fa1c73e4725133 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Sun, 10 Nov 2019 12:12:35 -0800 Subject: [PATCH 13/21] Remove semicolons, add way to break out of infinite loop --- ch_3_lesson_adam_hutchings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index 5197519..c9f14fd 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -81,7 +81,7 @@ def menu_function(): modification_function() valid_input = True -while True: +while True: #Mainloop valid_input_5 = False while valid_input_5 == False: menu_selection = input("""Type 'view' to view, From 9b1d17bb8afa8eae67b9ee078e4667fd0c2878b6 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Sun, 10 Nov 2019 14:23:44 -0800 Subject: [PATCH 14/21] Add escape options, remove semicolon. --- ch_3_lesson_adam_hutchings.py | 101 ++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index c9f14fd..e3e53d8 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -11,24 +11,40 @@ def remove_function(): break def view_function(): + if master_dictionary == {}: + print("You don't have any stored data.") + return None while True: - viewing_selection = input("Which team's statistics would you like to view? ") + viewing_selection = input("""Which team's statistics would you like to view? + You may also quit at any time by pressing q. """) if "statistics" + str(viewing_selection) in master_dictionary: break + elif viewing_selection == 'q': + print("Returning to main menu.") + return None + else: + print("That isn't a team.") while True: statistic_selection = input("""Which statistic would you like to view? Please type one of - tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), - cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). """) - if statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': +tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), +cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). +Again, you can quit with 'q'. """) + if statistic_selection == 'q': + print("Returning to main menu.") + break + elif statistic_selection in statistic_list and master_dictionary["statistics" + viewing_selection][statistic_selection] != '': print (master_dictionary["statistics" + viewing_selection][statistic_selection]) - break; + break elif master_dictionary["statistics" + viewing_selection][statistic_selection] == '': print("That hasn't been added yet. Try something else.") break def search_teams(): #Searching teams while True: - team_search = input("What team would you like to search for? ") + team_search = input("What team would you like to search for? You may also quit at any time by pressing q. ") + if team_search == 'q': + print("Returning to main menu.") + return None if team_search.isdigit() == False: #If the search is all digits print("Oops, enter a valid input!") continue @@ -41,10 +57,13 @@ def search_teams(): #Searching teams return ("No matches were found.") def add_team(): #How to add a new team - print("You are adding a new file. The first step is to name your team.") + print("You are adding a new file. The first step is to name your team. You may also quit at any time by pressing q. ") while True: team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team - if team_name.isdigit() == False: #Checking if a team name is all digits + if team_name == 'q': + print("Returning to the main menu. ") + break + elif team_name.isdigit() == False: #Checking if a team name is all digits print("Valid input, please!") continue else: @@ -57,7 +76,8 @@ def add_statistic(): #How to add a statistic for a team team_name = '' #Setting variables empty datapoint = '' while True: - team_name = input("Please select a team whose information you would like to modify.") #Finding the team + team_name = input("""Please select a team whose information you would like to modify. +You may also quit at any time by pressing q. """) #Finding the team if ("statistics" + str(team_name)) in master_dictionary: break while True: @@ -72,43 +92,32 @@ def add_statistic(): #How to add a statistic for a team datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint -def menu_function(): - if master_dictionary == {}: - valid_input = False - while valid_input == False: - first_input = input("You don't seem to have any data. Enter 'yes' to add some. ") - if first_input == 'yes': - modification_function() - valid_input = True - while True: #Mainloop - valid_input_5 = False - while valid_input_5 == False: - menu_selection = input("""Type 'view' to view, - 'remove' to remove, 'search' to search the teams, 'add' to add a team, or - 'statistic' to add a statistic to a team's file. - Or type 'stop' to end this program. """) - if menu_selection == 'view': - valid_input_5 = True - view_function() - elif menu_selection == 'remove': - valid_input_5 = True - remove_function() - elif menu_selection == 'search': + menu_selection = input("""Type 'view' to view, + 'remove' to remove, 'search' to search the teams, 'add' to add a team, or + 'statistic' to add a statistic to a team's file. + Or type 'stop' to end this program. """) + if menu_selection == 'view': + valid_input_5 = True + view_function() + elif menu_selection == 'remove': + valid_input_5 = True + remove_function() + elif menu_selection == 'search': + valid_input_5 = True + print(search_teams()) + elif menu_selection == 'add': + valid_input_5 = True + add_team() + elif menu_selection == 'statistic': + if master_dictionary != {}: valid_input_5 = True - print(search_teams()) - elif menu_selection == 'add': - valid_input_5 = True - add_team() - elif menu_selection == 'statistic': - if master_dictionary != {}: - valid_input_5 = True - add_statistic() - else: - print("You don't have any teams! Darn it!") - continue - elif menu_selection == 'stop': - break + add_statistic() else: - print('Enter a valid input! ') - continue \ No newline at end of file + print("You don't have any teams! Darn it!") + continue + elif menu_selection == 'stop': + break + else: + print('Enter a valid input! ') + continue \ No newline at end of file From ec67161fca9f6303f0b6edd6f6a4dc6e3f7100f7 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Sun, 10 Nov 2019 19:09:25 -0800 Subject: [PATCH 15/21] Remove "break" statement, add quit option for "remove_funcrion" --- ch_3_lesson_adam_hutchings.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index e3e53d8..abcc5ba 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -5,10 +5,14 @@ def remove_function(): while True: #Idiotproofing code - removal = input("Which team would you like to remove? This action cannot be undone!") - if ("statistics" + removal) in master_dictionary: + removal = input("Which team would you like to remove? This action cannot be undone! You may also quit at any time by pressing q. ") + if removal == 'q': + break + elif ("statistics" + removal) in master_dictionary: master_dictionary[removal] = {} break + else: + print("Enter a valid input!") def view_function(): if master_dictionary == {}: @@ -53,7 +57,6 @@ def search_teams(): #Searching teams for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search if search == ("statistics" + team_search): return ("A match has been found!") - break return ("No matches were found.") def add_team(): #How to add a new team From ca568b84ef3626b6f7c9fcf98bea071f20b70a9b Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Tue, 12 Nov 2019 21:43:09 -0800 Subject: [PATCH 16/21] Fix add_statistic function. --- ch_3_lesson_adam_hutchings.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index abcc5ba..e7ed039 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -49,7 +49,7 @@ def search_teams(): #Searching teams if team_search == 'q': print("Returning to main menu.") return None - if team_search.isdigit() == False: #If the search is all digits + if not team_search.isdigit(): #If the search is all digits print("Oops, enter a valid input!") continue else: @@ -88,12 +88,25 @@ def add_statistic(): #How to add a statistic for a team a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), and the number of drivetrain motors on your robot (dt). Which one of these options would you like to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. - if statistic_added in statistic_list: - break - for statistic_name in statistic_list: #For all possible statistic names - if statistic_added == statistic_name: #If the statistic selected has been found: - datapoint = (input("What would you like to set this team's " + statistic_added + "?")) #What data the user wants to add. - master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint + if statistic_added == 'q': + return None + elif statistic_added in statistic_list: + datapoint = (input("What would you like to set this team's " + statistic_added + " to?")) + if statistic_added == 'w' or 'l': + if not datapoint.isnum() + continue + elif statistic_added == 'cv': + if datapoint not in ['yes', 'no', 'True', 'False']: + continue + elif statistic_added == 'dt': + if not datapoint.isnum(): + continue + else: + continue + master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint + return None + else: + continue while True: #Mainloop menu_selection = input("""Type 'view' to view, From 85d957400064a10841fccd9f1d810e885434ce8c Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Tue, 12 Nov 2019 22:17:35 -0800 Subject: [PATCH 17/21] Fix issue with names, fix syntax errors. --- ch_3_lesson_adam_hutchings.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index e7ed039..dc2b7de 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -1,6 +1,6 @@ master_dictionary = {} #Setting up the master el dictionario input_list = ['menu', 'view', 'remove', 'search', 'modify'] -statistic_list = ['tm', 'n', 'pl', 'w', 'l', 'cv', 'dt'] +statistic_list = ['nm', 'tm', 'pl', 'w', 'l', 'cv', 'dt'] #Translating user inputs into functions def remove_function(): @@ -21,7 +21,7 @@ def view_function(): while True: viewing_selection = input("""Which team's statistics would you like to view? You may also quit at any time by pressing q. """) - if "statistics" + str(viewing_selection) in master_dictionary: + if ("statistics" + str(viewing_selection)) in master_dictionary: break elif viewing_selection == 'q': print("Returning to main menu.") @@ -30,7 +30,7 @@ def view_function(): print("That isn't a team.") while True: statistic_selection = input("""Which statistic would you like to view? Please type one of -tm (team number), n (name), pl (programming language), w or l (width or a length for your robot), +tm (team number), nm (name), pl (programming language), w or l (width or a length for your robot), cv (whether or not your robot has a camera vision system),or dt (the number of drivetrain motors on your robot). Again, you can quit with 'q'. """) if statistic_selection == 'q': @@ -62,17 +62,19 @@ def search_teams(): #Searching teams def add_team(): #How to add a new team print("You are adding a new file. The first step is to name your team. You may also quit at any time by pressing q. ") while True: - team_name = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team - if team_name == 'q': + team_number = input("What would you like your team to be named? Make sure it's all numbers! ") #Getting a name for the team + team_name = input("How about your team's name? ") + if team_number == 'q' or team_name == 'q': print("Returning to the main menu. ") break - elif team_name.isdigit() == False: #Checking if a team name is all digits + elif team_number.isdigit() == False: #Checking if a team name is all digits print("Valid input, please!") continue else: - master_dictionary["statistics" + str(team_name)] = {} #Making a dictionary entry for the team + master_dictionary["statistics" + str(team_number)] = {} #Making a dictionary entry for the team for yeet in statistic_list: - master_dictionary["statistics" + str(team_name)][yeet] = '' + master_dictionary["statistics" + str(team_number)][yeet] = '' + master_dictionary["statistics" + str(team_number)]['nm'] = team_name break def add_statistic(): #How to add a statistic for a team @@ -84,7 +86,7 @@ def add_statistic(): #How to add a statistic for a team if ("statistics" + str(team_name)) in master_dictionary: break while True: - statistic_added = input("""You may add a team number (tm), a name (n), a programming language (pl), + statistic_added = input("""You may add a team number (tm), change the name (nm), add a programming language (pl), a width or a length for your robot (w or l), whether or not your robot has a camera vision system (cv), and the number of drivetrain motors on your robot (dt). Which one of these options would you like to edit? Enter your options as the parenthetical after the option you have selected. """) #Note the shorthands like 'pl' here. @@ -93,8 +95,8 @@ def add_statistic(): #How to add a statistic for a team elif statistic_added in statistic_list: datapoint = (input("What would you like to set this team's " + statistic_added + " to?")) if statistic_added == 'w' or 'l': - if not datapoint.isnum() - continue + if not datapoint.isnum(): + continue elif statistic_added == 'cv': if datapoint not in ['yes', 'no', 'True', 'False']: continue From 56286a79a3b4f860c28bd6860baede48128790da Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Tue, 12 Nov 2019 22:31:34 -0800 Subject: [PATCH 18/21] Fix the adding odf statistics. --- ch_3_lesson_adam_hutchings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index dc2b7de..1de3c76 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -95,13 +95,16 @@ def add_statistic(): #How to add a statistic for a team elif statistic_added in statistic_list: datapoint = (input("What would you like to set this team's " + statistic_added + " to?")) if statistic_added == 'w' or 'l': - if not datapoint.isnum(): + if datapoint.isalpha(): + print("Invalid input.") continue elif statistic_added == 'cv': if datapoint not in ['yes', 'no', 'True', 'False']: + print("Invalid input.") continue elif statistic_added == 'dt': - if not datapoint.isnum(): + print("Invalid input.") + if datapoint.isalpha(): continue else: continue From 77c8f25c993fda01210ff8fa2de28c4f253e8428 Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Wed, 13 Nov 2019 22:42:30 -0800 Subject: [PATCH 19/21] Fix 'view' function, fix data storage. --- ch_3_lesson_adam_hutchings.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index 1de3c76..13bbffd 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -18,16 +18,20 @@ def view_function(): if master_dictionary == {}: print("You don't have any stored data.") return None - while True: + else: + x = True + while x == True: viewing_selection = input("""Which team's statistics would you like to view? You may also quit at any time by pressing q. """) - if ("statistics" + str(viewing_selection)) in master_dictionary: - break - elif viewing_selection == 'q': - print("Returning to main menu.") - return None - else: - print("That isn't a team.") + for team in master_dictionary: + if viewing_selection.isalpha() == False: + if team == ("statistics" + str(viewing_selection)): + x = False + elif viewing_selection == (master_dictionary[team])['nm']: + x = False + elif viewing_selection == 'q': + print("Returning to main menu.") + return None while True: statistic_selection = input("""Which statistic would you like to view? Please type one of tm (team number), nm (name), pl (programming language), w or l (width or a length for your robot), @@ -49,14 +53,12 @@ def search_teams(): #Searching teams if team_search == 'q': print("Returning to main menu.") return None - if not team_search.isdigit(): #If the search is all digits - print("Oops, enter a valid input!") continue else: break for search in master_dictionary: #Checking every master_dict key to see if it's equal to the search - if search == ("statistics" + team_search): - return ("A match has been found!") + if search == ("statistics" + team_search) or search == ("statistics" + team_search)['nm']: + return ("A match has been found! Team " + search + '.') return ("No matches were found.") def add_team(): #How to add a new team @@ -108,6 +110,10 @@ def add_statistic(): #How to add a statistic for a team continue else: continue + if statistic_added == 'w' or 'l' or 'dt': + statistic_added = int(statistic_added) + elif statistic_added == 'cv': + statistic_added = True if statistic_added == 'yes' or 'True' else False master_dictionary["statistics" + str(team_name)][statistic_added] = datapoint return None else: From dcd19efc0578a76d9c7b38d849b914b67bf5f1ef Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Thu, 14 Nov 2019 14:33:22 -0800 Subject: [PATCH 20/21] Fix indentation. --- ch_3_lesson_adam_hutchings.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index 13bbffd..5d71d33 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -19,19 +19,19 @@ def view_function(): print("You don't have any stored data.") return None else: - x = True - while x == True: - viewing_selection = input("""Which team's statistics would you like to view? - You may also quit at any time by pressing q. """) - for team in master_dictionary: - if viewing_selection.isalpha() == False: - if team == ("statistics" + str(viewing_selection)): + x = True + while x == True: + viewing_selection = input("""Which team's statistics would you like to view? + You may also quit at any time by pressing q. """) + for team in master_dictionary: + if viewing_selection.isalpha() == False: + if team == ("statistics" + str(viewing_selection)): + x = False + elif viewing_selection == (master_dictionary[team])['nm']: x = False - elif viewing_selection == (master_dictionary[team])['nm']: - x = False - elif viewing_selection == 'q': - print("Returning to main menu.") - return None + elif viewing_selection == 'q': + print("Returning to main menu.") + return None while True: statistic_selection = input("""Which statistic would you like to view? Please type one of tm (team number), nm (name), pl (programming language), w or l (width or a length for your robot), From 01edbf6c5c2aaad6f2bd61b8fdfa95aaea90f3fa Mon Sep 17 00:00:00 2001 From: Adam Hutchings Date: Thu, 14 Nov 2019 19:16:39 -0800 Subject: [PATCH 21/21] Fix bug. --- ch_3_lesson_adam_hutchings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch_3_lesson_adam_hutchings.py b/ch_3_lesson_adam_hutchings.py index 5d71d33..050f577 100644 --- a/ch_3_lesson_adam_hutchings.py +++ b/ch_3_lesson_adam_hutchings.py @@ -97,7 +97,7 @@ def add_statistic(): #How to add a statistic for a team elif statistic_added in statistic_list: datapoint = (input("What would you like to set this team's " + statistic_added + " to?")) if statistic_added == 'w' or 'l': - if datapoint.isalpha(): + if not datapoint.isdigit(): print("Invalid input.") continue elif statistic_added == 'cv':