From c0257d7145484b5294955ec6dc668a385754c994 Mon Sep 17 00:00:00 2001 From: "Andre Silva (mateussa)" Date: Mon, 13 Nov 2017 23:17:42 +0000 Subject: [PATCH] Changed determineUserInput codes for answer type input Reordered the numbers for the type of user input, to care for the diferent types of questions seperatly. Added a file to keep track of each input type code --- Server.py | 30 +++++++++++++++-------- __pycache__/Get_Functions.cpython-36.pyc | Bin 2077 -> 0 bytes determineUserInput.py | 14 +++++------ determineUserInputInfo.txt | 9 +++++++ 4 files changed, 36 insertions(+), 17 deletions(-) delete mode 100644 __pycache__/Get_Functions.cpython-36.pyc create mode 100644 determineUserInputInfo.txt diff --git a/Server.py b/Server.py index 4dc3ff8..b81b7c7 100644 --- a/Server.py +++ b/Server.py @@ -12,6 +12,7 @@ thisSocket.listen(1) # Connect to client conn, addr = thisSocket.accept() print ("The Connection ip is : " + str(addr)) +print(conn) def sendMessage(message, EOM = True): ''' Given a message input, and a False value, send the message and the @@ -57,21 +58,24 @@ def askSomething(answerType, sendMessages, noAnswers, defaultAnswer): answer = receiveMessage() print(answer) while ((answer[1] != answerType and len(noAnswers) > 0) or - ((answer[0] == "" or answer[1] in [0, 2]) and len(noAnswers) > 0)): + ((answer[0] == "" or answer[1] in [0, 2, 3, 4]) and len(noAnswers) > 0)): if(answerType == -1 and answer[1] == 0): for cat in sendMessages: - if (answer[0].casefold() == cat.casefold()): answer = (answer[0], -1) break break - if (answer[1] == 2): # If the use asked a questions + if (answer[1] in [2, 4]): # If the user asked a how or are question + sendMessage(answer[0], False) + sendMessage(noAnswers[0]) + noAnswers.pop(0) + elif (answer[1] == 3): # If the user asked a what question sendMessage("The answer to that is {}.".format(answer[0]), False) sendMessage(noAnswers[0]) noAnswers.pop(0) - elif (answer[1] in [4, 5]): # If the user doesn't want to answer + elif (answer[1] == 7): # If the user doesn't want to answer sendMessage("You should, it would be more fun!") noAnswers.pop(len(noAnswers) - 1) else: @@ -87,7 +91,7 @@ def askSomething(answerType, sendMessages, noAnswers, defaultAnswer): return (answer[0]) def qChallenge(): - ''' Question challenge, test user knowledge with some questions ''' + ''' Output a set of questions with a category choosen by the user ''' cat = getCategories(True, 3) if ("Error" in cat): sendMessage("{}: {}".format(cat[0], cat[1]), False) @@ -108,17 +112,19 @@ def qChallenge(): sendMessage(questionSet[1], False) sendMessage("Lets try again.", False) return (True) - + + # If question set of multiple type if (questionSet["Type"] == "multiple"): - receivedMessage = askSomething(3, [questionSet["Question"], + receivedMessage = askSomething(5, [questionSet["Question"], "A: {}".format(questionSet["A"]), "B: {}".format(questionSet["B"]), "C: {}".format(questionSet["C"]), "D: {}".format(questionSet["D"])], ["You can choose one of the options.", "Hmmm, I see you are afraid of making a mistake."], "X") + # If question set of boolean type else: - receivedMessage = askSomething(3, [questionSet["Question"], + receivedMessage = askSomething(5, [questionSet["Question"], "A: {}".format(questionSet["A"]), "B: {}".format(questionSet["B"])], ["You can choose one of the options.", @@ -127,7 +133,8 @@ def qChallenge(): if (receivedMessage[0].casefold() == questionSet["corrAnswer"].casefold()): sendMessage("Congratulations! That was the right answer!!", False) sendMessage("-" * 50, False) - receivedMessage = askSomething(4, ["Would you like to answer another question?"], + + receivedMessage = askSomething(6, ["Would you like to answer another question?"], ["Are you afraid?? :D.", "Hmmm, I see you are afraid of making a mistake."], "No") @@ -143,7 +150,8 @@ def qChallenge(): questionSet[questionSet["corrAnswer"]]), False) sendMessage("I know you can get the next one!!", False) sendMessage("-" * 50, False) - receivedMessage = askSomething(4, ["Would you like to answer another question?"], + + receivedMessage = askSomething(6, ["Would you like to answer another question?"], ["Are you afraid?? :D.", "Hmmm, I see you are afraid of making a mistake."], "No") @@ -153,6 +161,8 @@ def qChallenge(): sendMessage("Great! Lets try again.", False) return(True) + + # Say hi to client and get name clientName = askSomething(1, ["Hi! I am Jeff.", "I can give really nice challanges!", "What's your name?"], diff --git a/__pycache__/Get_Functions.cpython-36.pyc b/__pycache__/Get_Functions.cpython-36.pyc deleted file mode 100644 index 536bb5c0ce1caafb38f4bfa1a7d02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il}cp6&K<`wt;W1eb&A|Gt)%YlR< Y6JJpZXevHv(yjUHB7c3>@LN~@0UX0L`Tzg` diff --git a/determineUserInput.py b/determineUserInput.py index 67faa68..1fa1edd 100644 --- a/determineUserInput.py +++ b/determineUserInput.py @@ -22,15 +22,15 @@ def determineUserInput(sentence): sentenceParse.insert(0, " ".join(sentenceParse[0:2])) if sentenceParse[0] in questionStarters: # ------------- execute the "what is" code here --------------- - response = respondQuestion(sentence), 2 + response = respondQuestion(sentence) elif sentenceParse[0] in greetings: response = getName(sentence), 1 elif sentence in "abcd": - response = sentence, 3 + response = sentence, 5 elif (sentence.casefold() == "Yes".casefold()) or (sentence.casefold() == "No".casefold()): - response = sentence, 4 + response = sentence, 6 elif sentence in notAnswer: - response = sentence, 5 + response = sentence, 7 else: response = sentence, 0 return response @@ -57,11 +57,11 @@ feelingList = ["feeling great","feeling good","fine","well","great","good"] def respondQuestion(sentence): newSentence = sentence.split() if newSentence[0] in ["how","hows"]: - response = executeHow(sentence) + response = executeHow(sentence), 2 elif newSentence[0] in ["what","whats"]: - response = executeWhat(sentence) + response = executeWhat(sentence), 3 elif newSentence[0] == "are": - response = executeAre(sentence) + response = executeAre(sentence), 4 return response diff --git a/determineUserInputInfo.txt b/determineUserInputInfo.txt new file mode 100644 index 0000000..1c3e2c9 --- /dev/null +++ b/determineUserInputInfo.txt @@ -0,0 +1,9 @@ +##### Return Input Type Code ##### +0 - Not Recognized +1 - Get Name From Sentence +2 - How Question +3 - What Question +4 - Are Question +5 - ACBD Answer Question Choice +6 - Yes/ No Answer +7 - Don't Want To Answer