CPSC 231 Tutorial Exercise 3 and Homework Assignment 3 Creating a Chatbot for a Bank (Learning Objective: understand the use of functions, and various data structures)Tutorial Exercise 3 ...

1 answer below »
homework assignment 3 and not tutorial exercise 3


CPSC 231 Tutorial Exercise 3 and Homework Assignment 3 Creating a Chatbot for a Bank (Learning Objective: understand the use of functions, and various data structures) Tutorial Exercise 3 Weight: 1.25% of final grade Submission: Nothing Demonstrate your code to your tutorial TA. You may demonstrate as many times as you wish until you get it right. Your TA can provide feedback each time you demonstrate. To receive marks for the exercise, you must demonstrate to your TA before the end of your enrolled tutorial session on either Wednesday November 2nd or Thursday November 3rd. Due to the severe weather conditions, in the interest of fairness to all students and to the safety of our students, if you can't make it to your tutorial session Wednesday Nov 2nd or Thursday Nov 3rd, that is okay. Stay safe and you can show your tutorial exercise to your TA the week after Reading Week in your tutorials. Detailed Descriptions Chatbots are being used everywhere nowadays to help customers with simple questions (and to enable these greedy cooperations to save money on customer support). If you go to the website of any big banks, you will see an icon for a web-based chatbot. In this exercise, you will start to create your own chatbot, called Riley, for a hypothetical bank in Canada called the Bank of Rabbits. Step 1: Create a new py file to work on. Name your file support_functions.py. If it is not called this name, rename it. Step 2: Download the new file, main.py, from D2L. main.py must be placed in the same directory as your own support_functions.py file. Step 3: Do not change anything in main.py. Start writing all your code in support_functions.py. You are allowed to import math, numpy. Nothing else should be imported. In your code, do not import main! It is the other way around: main.py imports support_functions. Except the import statements (if you choose to import math or numpy), you should not have any code that is outside a function. Import must happen at the top of the code. All your other code should be defined inside a function. Your functions are going to be used by main.py. You can use anything else that is not forbidden in this document. Step 4: Your first job is to ensure the files are set up correctly. Run main.py (do not run support_functions.py). You should see the following: Starting server on 127.0.0.1:8080. The Python code is creating a web server on your local computer. The server will keep running until you stop the Python program (or until you crash it with some error in your code). Now open a web browser (Chrome, Firefox, Edge, etc. but avoid Safari) and go to https://pages.cpsc.ucalgary.ca/~richard.zhao1/rabbits/ You should see: https://pages.cpsc.ucalgary.ca/~richard.zhao1/rabbits/ (While keeping your Python code running) Click the button "Connect to server". If you see the following message in your web browser, you've set up correctly. This web page (called a client) is able to connect with the Python-based server running on your computer. If you don't see the "Connected!" message, your server is not running on the same machine as your web page. For the tutorial exercise: Step 5: your task is to create a new custom function in your support_functions.py file, called get_greetings(name). The function has the following: Parameter: name, a string. Optional. Returns: a string. name is an optional parameter – meaning that the function can be called with an argument, or without (read lecture 13 on optional parameters!). Your code must handle both cases. Case 1: If the function is called with a name, the function should return the following string: "Greetings ! I am Riley, your virtual assistant at Bank of Rabbits." Here should be whatever the value of the name parameter is. As an example, if the function is called with "John": get_greetings("John") then the returned string should be "Greetings John! I am Riley, your virtual assistant at Bank of Rabbits." Note that this string is a return value of the function. It is not an output, so you should not print it. Note: This is different than assignments 1 and 2 where you are printing the results to the screen. To test your code, stop the running Python code first, and restart it. You must restart the server each time you make a change to your Python code. Go to the webpage, and type in any name, and click "Connect to Server". You should see the following: Step 6: Case 2: If the function is called without a name: get_greetings() the function should return the following string: "Hey you! I am Riley, your virtual assistant at Bank of Rabbits." After you complete this, when the "Your name" textbox is empty and you click "Connect to Server", you should see this: Demonstrate to your TA that you have done this work. Homework Assignment 3 Weight: 7% of final grade Due date: Friday November 18th, at 11:59pm Estimated time needed to complete Assignment 3: about 1.5 times what you spent on Assignment 2. Submission: one support_functions.py file only, submit on the D2L Dropbox. You may submit as many times as you wish, and only the latest submission will be marked. Late Submissions: Submitting on November 19th will use up one personal day. Submitting on November 20th will use up two personal days, etc. You have a total of 5 personal days for the entire semester. No penalties for using personal days. An assignment will not be accepted if it is late and all personal days are already used. Academic Integrity: This work must be completed individually. Please follow academic integrity rules as discussed during lecture. You may discuss your ideas in English (not in Python) with other students as much as you like, but make sure that when you write your code that it is your own. A good rule of thumb is to never let anyone else see your code, except your instructor and TAs. Detailed Descriptions Continue working from your tutorial exercise file. Step 1: We will need to create a helper function that your other functions can use. Create a new custom function in your support_functions.py file, called is_whole_word(word, sentence). Create this function from scratch using your own code. The function has the following: Parameters: word, a string. sentence, a string. Returns: a tuple of two elements - Boolean, int The Boolean return value is True if the word exists as a whole word in the sentence. False otherwise. The int return value is the index of the word if it exists as a whole word in the sentence. -1 otherwise. A whole word is defined to be a word that is not a part of another word. For example: • In the sentence "oh hi you!", "hi" is a whole word, so the function should return (True, 3). The index is 3 since "hi" is at index 3 of the sentence. • In the sentence, "high up in the sky", the word "hi" does not exist as a whole word since it is a part of "high", so the function should return (False, -1). • If the word does not appear at all in the sentence, the function returns (False, -1). Given parameter values when function is called: Function should return: is_whole_word("hi", "oh hi you!") (True, 3) is_whole_word("hi", "high up in the sky!") (False, -1) This function is case insensitive – meaning any combination of upper/lower case words are accepted as valid, so "HI" counts as appearing in "hi you." Note: this is a different requirement than assignment 1. Step 2: Now we can go back to creating Riley. Riley should be able to answer basic greetings. Create a new custom function in your support_functions.py file, called get_basic_answers(question, name). The function has the following: Parameters: question, a string. name, a string. Optional. Returns: a string. If the question contains one greeting word, this function should return the same greeting word in the proper case, followed by one space and name, if a name is given, followed by "!". See examples below. Greeting words are defined to only be "Greetings", "Hello", "Hi", "Hey", "Good morning", "Good afternoon", "Good evening". The words are case insensitive. Examples without name parameter: Given parameter values when function is called: Function should return: get_basic_answers("Hello!") "Hello!" get_basic_answers("Hello you!") "Hello!" get_basic_answers("riley! hELLO !") "Hello!" get_basic_answers("buddy good morning") "Good morning!" get_basic_answers("Riley! GoOd AfTeRnOoN!") "Good afternoon!" get_basic_answers("Greetings, Riley!") "Greetings!" Examples with name parameter: Given parameter values when function is called: Function should return: get_basic_answers("Hello!", "Alice") "Hello Alice!" get_basic_answers("Hey!", "bob") "Hey bob!" get_basic_answers("riley! hELLO !", "CATHY") "Hello CATHY!" get_basic_answers("buddy good morning", "D.J.") "Good morning D.J.!" Step 3: If more than 1 greetings words exist in question, only the first one that appeared in the question is used for the returned string. Given parameter values when function is called: Function should return: get_basic_answers("hi good morning hi!") "Hi!" get_basic_answers("yo heY riley! Good evening !") "Hey!" Step 4: If no greeting words exist in question, the function returns the string "Sorry, I do not understand." Examples: Given parameter values when function is called: Function should return: get_basic_answers("yo riley") "Sorry, I do not understand." get_basic_answers("high up in the sky!", "Adam") "Sorry, I do not understand." Greeting words cannot be a part of another word. When in doubt, think: does this make sense in English? You may test your code with the webpage. Step 5: Riley should be able to answer questions about banking. Create a new custom function in your support_functions.py file, called get_answers(q_and_a, question). The function has the following: Parameters: q_and_a, a dictionary question
Answered 3 days AfterNov 13, 2022

Answer To: CPSC 231 Tutorial Exercise 3 and Homework Assignment 3 Creating a Chatbot for a Bank (Learning...

Nidhi answered on Nov 17 2022
56 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here