From 12acc04521a428149b1b4d6dcfebb18c973495b6 Mon Sep 17 00:00:00 2001 From: Merilyn Chesler Date: Tue, 16 Jul 2019 14:31:20 -0400 Subject: [PATCH 1/2] replace raw_input with input --- U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt1.py | 2 +- U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt2.py | 4 ++-- U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt3.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt1.py b/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt1.py index e102cac..3302a84 100644 --- a/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt1.py +++ b/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt1.py @@ -22,7 +22,7 @@ # Iterate over the list of survey questions and take in user responses. for x in range(len(survey)): - response = raw_input(survey[x] +": ") + response = input(survey[x] +": ") answers[keys[x]] = response # Print the entire dictionary. diff --git a/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt2.py b/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt2.py index 6f7edca..0f2b3f0 100644 --- a/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt2.py +++ b/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt2.py @@ -31,12 +31,12 @@ # Iterate over the list of survey questions and take in user responses. for x in range(len(survey)): - response = raw_input(survey[x] +": ") + response = input(survey[x] +": ") answers[keys[x]] = response list_of_answers.append(answers) - done = raw_input("Are you done collecting information? Type YES or NO. ").upper() + done = input("Are you done collecting information? Type YES or NO. ").upper() # Print the list of dictionaries. print(list_of_answers) diff --git a/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt3.py b/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt3.py index d298926..f13c56f 100644 --- a/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt3.py +++ b/U2-Applications/U2.1-Data/SurveyProject/surveyproject_pt3.py @@ -30,11 +30,11 @@ # Iterate over the list of survey questions and take in user responses. for x in range(len(survey)): - response = raw_input(survey[x] +": ") + response = input(survey[x] +": ") answers[keys[x]] = response list_of_answers.append(answers) - done = raw_input("\nAre you done collecting information? Type YES or NO. ") + done = input("\nAre you done collecting information? Type YES or NO. ") # Open the file containing all past results and append them to our current list. f = open("allanswers.json", "r") From a09d14d2eddd0c24a613d088ea29072b10db8985 Mon Sep 17 00:00:00 2001 From: Merilyn Chesler Date: Tue, 16 Jul 2019 14:38:57 -0400 Subject: [PATCH 2/2] Simply logic for is_valid_input(user_input, valid_responses) --- U1-Fundamentals/U1.2-Python/chatbot/chatbot-pt4.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/U1-Fundamentals/U1.2-Python/chatbot/chatbot-pt4.py b/U1-Fundamentals/U1.2-Python/chatbot/chatbot-pt4.py index 31a9bfa..9332289 100644 --- a/U1-Fundamentals/U1.2-Python/chatbot/chatbot-pt4.py +++ b/U1-Fundamentals/U1.2-Python/chatbot/chatbot-pt4.py @@ -26,15 +26,9 @@ def say_default(): # Check if user_input matches one of the elements # in valid_responses. def is_valid_input(user_input, valid_responses): - for item in valid_responses: - if user_input == item: - # If you find a matching response, the input is - # valid for this kind of response. - return True - # If you didn't find a matching response, after - # going through the entire list, the input - # isn't valid for this kind of response. - return False + if user_input in valid_responses: + return True + return False # --- Put your main program below! --- def main(): @@ -46,4 +40,4 @@ def main(): # DON'T TOUCH! Setup code that runs your main() function. if __name__ == "__main__": - main() \ No newline at end of file + main()