Browse Source

Add Sal's Shipping and customer service bot files.

master
Josh Mudge 5 years ago
parent
commit
194825da3d
  1. 47
      Codecadmey Projects/Salshipping.py
  2. 500
      Codecadmey Projects/customer_service_bot/.ipynb_checkpoints/customer_service_bot-checkpoint.ipynb
  3. 500
      Codecadmey Projects/customer_service_bot/customer_service_bot.ipynb
  4. 570
      Codecadmey Projects/customer_service_bot/customer_service_bot_solution.ipynb
  5. 25
      Codecadmey Projects/ex7_ch5?.py

47
Codecadmey Projects/Salshipping.py

@ -0,0 +1,47 @@
premium_ground_shipping = 125.00
def ground_shipping(weight):
flat = 20.00
if weight <= 2:
cost = flat + 1.50 * weight
if (weight > 2) and (weight <= 6):
cost = flat + weight * 3.00
if (weight > 6) and (weight <= 10):
cost = flat + weight * 4.00
if (weight > 10):
cost = flat + weight * 4.75
return cost
def drone_shipping(weight):
if (weight <= 2):
cost = weight * 4.50
elif (weight > 2) and (weight <= 6):
cost = weight * 9.00
elif (weight > 6) and (weight >= 10):
cost = weight * 12.00
else:
cost = weight * 14.25
return cost
def shipping_cost(weight):
ground = ground_shipping(weight)
drone = drone_shipping(weight)
if ground < premium_ground_shipping and ground < drone:
cost = ground_shipping(weight)
return "Ground Shipping is the cheapest option! It will cost: $%s" % cost
elif drone < premium_ground_shipping and drone < ground:
cost = drone_shipping(weight)
return "Drone Shipping is the cheapest option! It will cost $%s" % cost
elif premium_ground_shipping < ground and premium_ground_shipping < drone:
cost = premium_ground_shipping
return "Premium Ground Shipping is the cheapest option! It will cost $%s" % cost
print(shipping_cost(1.5))
print(shipping_cost(4.8))
print(shipping_cost(41.5))

500
Codecadmey Projects/customer_service_bot/.ipynb_checkpoints/customer_service_bot-checkpoint.ipynb

@ -0,0 +1,500 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Off-Platform Project 1: Customer Service Bot\n",
"\n",
"Hi there! In this off-platform project, you will be working as a software engineer for the **Definitely Not Sinister Cable Company**! They have hired you to build a bot that can handle basic customer service requests on their website.\n",
"\n",
"First, you will learn a little bit about handling user input, then we will jump right in and start building the functions you need to generate an interactive customer serivce bot.\n",
"\n",
"Let's get started!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Input( )\n",
"\n",
"In Python 3, you can handle basic user text input by using the built-in function `input()`. This is how we will have users interact with your customer service bot. You use `input()` by defining a variable and setting it equal to `input(\"text the user is responding to\")`. \n",
"\n",
"Run the following two code blocks to see how `input()` works."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"What is your name? Josh\n"
]
}
],
"source": [
"name = input(\"What is your name? \")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Josh\n"
]
}
],
"source": [
"print(name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Your response to the question \"What is your name?\" was stored in the variable `name`, which was then printed in the next cell. Great, that's all you need to know for now! Let's get started building the customer service bot!\n",
"\n",
"## Step 1\n",
"\n",
"Before going any further, Go to the 'Cell' drop down at the menu at the top of this notebook and select 'Run All'. This will run all of the cells below so that everything we need to build the customer service bot is ready.\n",
"\n",
"## Step 2\n",
"\n",
"Great, let's get started. First in the cell below, define the function `cs_service_bot`. This will be our main function. Every time a user accesses our support, this function will be called and will guide them through a decision tree to identify their support needs and find them a solution.\n",
"\n",
"1. This function should start by printing:\n",
" Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\n",
" [1] New Customer\n",
" [2] Existing Customer\n",
" You can store this all in a single string and use the escape character `\\n` to indicate line breaks.\n",
"\n",
"2. Next we want to ask them to choose an option. We are going to do that using `input()`. Make a variable called `response` and have it save the users response using `input()`. You should include text to let the user know how they should make their choice, such as:\n",
" Please enter the number corresponding to your choice: \n",
"3. If the user selects `1` the function should direct them to another function `new_customer()`. We will define this function later.\n",
"4. If the user selects `2` the function should direct them to another function `existing_customer()`. We will define this function later as well.\n",
"5. Finally, if the user enters something other than a `1` or `2` we want our function to print \n",
" Sorry, we didn't understand your selection.\n",
" and then run `cs_service_bot` again to let them make another choice."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"def cs_service_bot():\n",
" print(\"Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\\n[1] New Customer\\n[2] Existing Customer\\n\")\n",
" response = input(\"Please enter a number corresponding to your choice.\")\n",
" \n",
" if response == \"1\":\n",
" new_customer() \n",
" elif response == \"2\":\n",
" existing_customer()\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\\n\")\n",
" cs_service_bot()\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Great Job! Run `cs_service_bot()` in the cell below and see how it works."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\n",
"[1] New Customer\n",
"[2] Existing Customer\n",
"\n",
"Please enter a number corresponding to your choice.2\n",
"\n",
"What kind of support do you need?\n",
"\n",
"[1] Television Support\n",
"[2] Internet Support\n",
"[3] Speak to a support representative.3\n"
]
},
{
"ename": "NameError",
"evalue": "name 'live_rep' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-27-e2536fcc94ec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcs_service_bot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-26-6b9d14688989>\u001b[0m in \u001b[0;36mcs_service_bot\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mnew_customer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"2\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mexisting_customer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Sorry, we didn't understand your selection.\\n\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-25-82748c8de2e9>\u001b[0m in \u001b[0;36mexisting_customer\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0minternet_support\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"3\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mlive_rep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Sorry, we didn't understand yoru selection.\\n\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'live_rep' is not defined"
]
}
],
"source": [
"cs_service_bot()"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Cool! We have the initial skeleton done, now we have to define `new_customer()` and `existing_customer()`.By breaking up our bot into a bunch of smaller functions we can build each piece incrementally and check our progress as we slowly build a fully functioning product.\n",
"\n",
"## Step 3\n",
"Let's start with `existing_customer()`. The options **DNS Cable Company** wants users to be able to select are \n",
"\n",
" [1] Television Support\n",
" [2] Internet Support\n",
" [3] Speak to a support representative. \n",
"\n",
"Have `existing_customer()` print \"What kind of support do you need?\" and then these three options. Remember, use the escape character `\\n` in strings for line breaks. Use `input()` in the same way as the previous function to record the users choice.\n",
"\n",
"1. If they select `1`, call the function `television_support()` which will we define later.\n",
"2. If they select `2`, call the function `internet_support()` which we will also define later.\n",
"3. If they select `3`, call the function `live_rep()` with the argument `\"support\"`. We'll use this argument to indicate what type of live representative the user will talk to. We will define the function later.\n",
"4. Finally, just like the `cs_service_bot()` function, if the user enters something other than the three options above, have the function print\n",
" Sorry, we didn't understand your selection.\n",
"and call itself to let them try again."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"def existing_customer():\n",
" response = input(\"\\nWhat kind of support do you need?\\n\\n[1] Television Support\\n[2] Internet Support\\n[3] Speak to a support representative.\")\n",
" if response == \"1\":\n",
" television_support()\n",
" elif response == \"2\":\n",
" internet_support()\n",
" elif response == \"3\":\n",
" live_rep()\n",
" else:\n",
" print(\"Sorry, we didn't understand yoru selection.\\n\")\n",
" existing_customer()\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4\n",
"You can see that we've introduced a whole new slew of functions as options of `existing_customer()`, and we'll define those soon but first let's define `new_customer()`.\n",
"\n",
"The options the **DNS Cable Company** wants for `new_customer()` are \n",
" \n",
" [1] Sign up for service.\n",
" [2] Schedule a home visit.\n",
" [3] Speak to a sales representative.\n",
" \n",
"They also want this function to greet their potential new customers with the phrase \"We're excited to have you join the DNS family, how can we help you?\" A little cheesy if you ask me but hey, the client is always right.\n",
"\n",
"1. If the user selects `1`, call the function `sign_up()`.\n",
"2. If the user selects `2`, call the function `home_visit()`.\n",
"3. If the user selects `3`, call the function `live_rep()` with the argument `\"sales\"` so the program directs them to the correct live representative.\n",
"4. Finally, like the other functions, if the user sumbits something other than the options above, display an error message and call the function again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def new_customer():\n",
" response = input(\"We're excited to have you join the DNS family, how can we help you?\")\n",
" if response == \"1\":\n",
" sign_up()\n",
" if response == \"2\":\n",
" home_visit()\n",
" if response == \"3\":\n",
" live_rep(sales)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 5\n",
"\n",
"Now it's time to dive down another level and start defining the next level of functions. Let's start with `television_support()`. **DNS Cable Company** has compiled the three most frequently reported issues and wants those to be surfaced as options in the bot as follows after the prompt \"What is the nature of your problem?\":\n",
"\n",
" [1] I can't access certain channels.\n",
" [2] My picture is blurry.\n",
" [3] I keep losing service.\n",
" \n",
"They also want a fourth catch-all option\n",
"\n",
" [4] Other issues.\n",
" \n",
"Now, for each of these options, they want to give the user the most useful advice they have.\n",
"\n",
"1. If the user enters `1` they want to print the following message and then call the function `did_that_help()` which we will define next. \n",
" Please check the channel lists at DefinitelyNotSinister.com. If the channel you cannot access is there, please contact a live representative.\n",
"2. If the user enters `2` they want to print the following message and then call the function `did_that_help()`\n",
" Try adjusting the antenna above your television set.\n",
"3. If the user enters `3` they want to print the following message and then call the function `did that help()`\n",
" Is it raining outside? If so, wait until it is not raining and then try again.\n",
"4. If the user enters `4` it should direct them immediately to `live_rep(\"support\")`\n",
"5. Just like the other functions, if the user enters something other than these options it should present an error message and call the function again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def television_support():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 6\n",
"\n",
"Next, we will define `internet_support()`, which is will be extremely similar to the function you just defined, `television_support()` except with different possible support issues. Here are the issues that **DNS Cable Company** wants included:\n",
"\n",
" [1] I can't connect to the internet.\n",
" [2] My connection is very slow.\n",
" [3] I can't access certain sites.\n",
" \n",
"Just like for television support, they also want a fourth option for `Other Issues`.\n",
"\n",
"They've highlighted these suggested fixes for each of the issues:\n",
"\n",
"1. If the user selects `1`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Unplug your router, then plug it back in, then give it a good whack, like the Fonz.\n",
"2. If the user selects `2`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Make sure that all cell phones and other peoples computers are not connected to the internet, so that you can have all the bandwidth.\n",
"3. If the user selects `3`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Move to a different region or install a VPN. Some areas block certain sites.\n",
"4. If the user selects `4`, the function should call `live_rep(\"support\")`\n",
"5. Finally, if the user enters something other than the options above, print an error message and recall the function."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def internet_support():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 7\n",
"\n",
"Great work! The last two functioned called the function `did_that_help()`, which we will define now. The purpose of `did_that_help()` is to check if the user was helped by the solution to their problem, and if not, ask them if they'd rather speak to a live representative over the phone or schedule a home visit.\n",
"\n",
"The structure of the function should be as followed:\n",
"1. Ask the user if the solution solved their problem and have them answer Yes or No using `input()`.\n",
"2. If yes, thank them.\n",
"3. If no, prompt them with another question and ask them if they would rather talk to a live representative or schedule a home visit.\n",
"4. If they want to talk to a representative, call `live_rep(\"support\")`\n",
"5. If they want to schedule a home visit, call `home_visit(\"support\")`\n",
"6. Make sure to include error messages for both user responses if they enter a choice not listed above"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def did_that_help():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 8\n",
"Now we've defined all of the initial options of `existing_customer()`, so we'll move onto the options for `new_customer()`, first let's define `sign_up()`.\n",
"\n",
"**DNS Cable Company** is very specific about the greeting they want new customers to see:\n",
"\n",
" Great choice, friend! We're excited to have you join the DNS family! Please select the package you are interested in signing up for.\n",
" [1] Bundle Deal (Internet + Cable)\n",
" [2] Internet\n",
" [3] Cable\n",
" \n",
"Apparently, they want their users to be forced to sign up if they reach this stage! Here's what they want each option to do:\n",
"\n",
"1. If a user selects `1`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Bundle Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"2. If a user selects `2`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Internet Only Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"3. If a user selects `3`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Cable Only Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"4. If a user enters something other than the above choices, print an error message and call `sign_up()` again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def sign_up():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Step 9\n",
"Now we've got an interesting function to define, `home_visit()`. We've called `home_visit()` in three different ways in other functions. In `new_customer()` we call `home_visit()` with no argument, in `internet_support()` and `television_support()` we call `home_visit(\"support\")`, and in `sign_up()` we call `home_visit(\"new install\")`.\n",
"\n",
"This means we want `home_visit()` to take a parameter, which we can call `purpose`, but we want this parameter to be optional with a default value of `\"none\"`.\n",
"\n",
"Now, `home_visit()` should first check `purpose` and then do one of the following:\n",
"1. If `purpose == \"none\"`, we need to determine the purpose of the home visit, so ask the user what the purpose of the home visit is and give them the options\n",
" [1] New service installation.\n",
" [2] Exisitng service repair.\n",
" [3] Location scouting for unserviced region.\n",
" 1. If they select `1` here, call `home_visit(\"new install\")`\n",
" 2. If they select `2` here, call `home_visit(\"support\")`\n",
" 3. If they select `3` here, call `home_visit(\"scout\")`\n",
"\n",
"For all other options, first ask the user\n",
" \n",
" Please enter a date below when you are available for a technician to come to your home and [PURPOSE SPECIFC TEXT HERE].\n",
"\n",
"and save their response to the variable `visit_date`, then respond \n",
" \n",
" Wonderful! A technical will come visit you on [visit_date]. Please be available between the hours of 1:00 am and 11:00 pm.\n",
" \n",
"and return `visit_date`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def home_visit():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Step 10\n",
"Great work! We have one last function to define! `live_rep()` is called by several different functions, but it always called with one of two arguments, `\"sales\"` or `\"support\"`. All this function needs to do is print a message to the user based on the argument.\n",
"\n",
"1. If the function is called with an argument of `\"sales\"`, print \n",
" Please hold while we connect you with a live sales representative. The wait time will be between two minutes and six hours. We thank you for your patience.\n",
"2. If the function is called with an argument of `\"support\"`, print \n",
" Please hold while we connect you with a live support representative. The wait time will be between two minutes and six hours. We thank you for your patience."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def live_rep(purpose):\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 11\n",
"\n",
"That's it, your customer service bot should be up and running! Test your code and run `cs_service_bot` and go through some of the choices! Make sure all of your options work and you end up where you expect after each decision."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cs_service_bot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## You're Done!\n",
"\n",
"Great work! Using very simple functions and conditional stables you were able to build a working customer service bot! While it might be a little limited in it's current state, you can always keep adding to it, making each individual function more robust. Some suggestions, try adding in a option to each menu that allows the user to exit without clicking through the entire tree.\n",
"\n",
"You can even build other types of projects using similar techniques! Try building a chat bot that can respond to what you say and ask you questions, or create a text based adventure game where players can make choices to do different actions.\n",
"\n",
"The possibilities are endless! So keep going and happy programming!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

500
Codecadmey Projects/customer_service_bot/customer_service_bot.ipynb

@ -0,0 +1,500 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Off-Platform Project 1: Customer Service Bot\n",
"\n",
"Hi there! In this off-platform project, you will be working as a software engineer for the **Definitely Not Sinister Cable Company**! They have hired you to build a bot that can handle basic customer service requests on their website.\n",
"\n",
"First, you will learn a little bit about handling user input, then we will jump right in and start building the functions you need to generate an interactive customer serivce bot.\n",
"\n",
"Let's get started!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Input( )\n",
"\n",
"In Python 3, you can handle basic user text input by using the built-in function `input()`. This is how we will have users interact with your customer service bot. You use `input()` by defining a variable and setting it equal to `input(\"text the user is responding to\")`. \n",
"\n",
"Run the following two code blocks to see how `input()` works."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"What is your name? Josh\n"
]
}
],
"source": [
"name = input(\"What is your name? \")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Josh\n"
]
}
],
"source": [
"print(name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Your response to the question \"What is your name?\" was stored in the variable `name`, which was then printed in the next cell. Great, that's all you need to know for now! Let's get started building the customer service bot!\n",
"\n",
"## Step 1\n",
"\n",
"Before going any further, Go to the 'Cell' drop down at the menu at the top of this notebook and select 'Run All'. This will run all of the cells below so that everything we need to build the customer service bot is ready.\n",
"\n",
"## Step 2\n",
"\n",
"Great, let's get started. First in the cell below, define the function `cs_service_bot`. This will be our main function. Every time a user accesses our support, this function will be called and will guide them through a decision tree to identify their support needs and find them a solution.\n",
"\n",
"1. This function should start by printing:\n",
" Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\n",
" [1] New Customer\n",
" [2] Existing Customer\n",
" You can store this all in a single string and use the escape character `\\n` to indicate line breaks.\n",
"\n",
"2. Next we want to ask them to choose an option. We are going to do that using `input()`. Make a variable called `response` and have it save the users response using `input()`. You should include text to let the user know how they should make their choice, such as:\n",
" Please enter the number corresponding to your choice: \n",
"3. If the user selects `1` the function should direct them to another function `new_customer()`. We will define this function later.\n",
"4. If the user selects `2` the function should direct them to another function `existing_customer()`. We will define this function later as well.\n",
"5. Finally, if the user enters something other than a `1` or `2` we want our function to print \n",
" Sorry, we didn't understand your selection.\n",
" and then run `cs_service_bot` again to let them make another choice."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"def cs_service_bot():\n",
" print(\"Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\\n[1] New Customer\\n[2] Existing Customer\\n\")\n",
" response = input(\"Please enter a number corresponding to your choice.\")\n",
" \n",
" if response == \"1\":\n",
" new_customer() \n",
" elif response == \"2\":\n",
" existing_customer()\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\\n\")\n",
" cs_service_bot()\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Great Job! Run `cs_service_bot()` in the cell below and see how it works."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\n",
"[1] New Customer\n",
"[2] Existing Customer\n",
"\n",
"Please enter a number corresponding to your choice.2\n",
"\n",
"What kind of support do you need?\n",
"\n",
"[1] Television Support\n",
"[2] Internet Support\n",
"[3] Speak to a support representative.3\n"
]
},
{
"ename": "NameError",
"evalue": "name 'live_rep' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-27-e2536fcc94ec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcs_service_bot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-26-6b9d14688989>\u001b[0m in \u001b[0;36mcs_service_bot\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mnew_customer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"2\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mexisting_customer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Sorry, we didn't understand your selection.\\n\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-25-82748c8de2e9>\u001b[0m in \u001b[0;36mexisting_customer\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0minternet_support\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"3\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mlive_rep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Sorry, we didn't understand yoru selection.\\n\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'live_rep' is not defined"
]
}
],
"source": [
"cs_service_bot()"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Cool! We have the initial skeleton done, now we have to define `new_customer()` and `existing_customer()`.By breaking up our bot into a bunch of smaller functions we can build each piece incrementally and check our progress as we slowly build a fully functioning product.\n",
"\n",
"## Step 3\n",
"Let's start with `existing_customer()`. The options **DNS Cable Company** wants users to be able to select are \n",
"\n",
" [1] Television Support\n",
" [2] Internet Support\n",
" [3] Speak to a support representative. \n",
"\n",
"Have `existing_customer()` print \"What kind of support do you need?\" and then these three options. Remember, use the escape character `\\n` in strings for line breaks. Use `input()` in the same way as the previous function to record the users choice.\n",
"\n",
"1. If they select `1`, call the function `television_support()` which will we define later.\n",
"2. If they select `2`, call the function `internet_support()` which we will also define later.\n",
"3. If they select `3`, call the function `live_rep()` with the argument `\"support\"`. We'll use this argument to indicate what type of live representative the user will talk to. We will define the function later.\n",
"4. Finally, just like the `cs_service_bot()` function, if the user enters something other than the three options above, have the function print\n",
" Sorry, we didn't understand your selection.\n",
"and call itself to let them try again."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"def existing_customer():\n",
" response = input(\"\\nWhat kind of support do you need?\\n\\n[1] Television Support\\n[2] Internet Support\\n[3] Speak to a support representative.\")\n",
" if response == \"1\":\n",
" television_support()\n",
" elif response == \"2\":\n",
" internet_support()\n",
" elif response == \"3\":\n",
" live_rep()\n",
" else:\n",
" print(\"Sorry, we didn't understand yoru selection.\\n\")\n",
" existing_customer()\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4\n",
"You can see that we've introduced a whole new slew of functions as options of `existing_customer()`, and we'll define those soon but first let's define `new_customer()`.\n",
"\n",
"The options the **DNS Cable Company** wants for `new_customer()` are \n",
" \n",
" [1] Sign up for service.\n",
" [2] Schedule a home visit.\n",
" [3] Speak to a sales representative.\n",
" \n",
"They also want this function to greet their potential new customers with the phrase \"We're excited to have you join the DNS family, how can we help you?\" A little cheesy if you ask me but hey, the client is always right.\n",
"\n",
"1. If the user selects `1`, call the function `sign_up()`.\n",
"2. If the user selects `2`, call the function `home_visit()`.\n",
"3. If the user selects `3`, call the function `live_rep()` with the argument `\"sales\"` so the program directs them to the correct live representative.\n",
"4. Finally, like the other functions, if the user sumbits something other than the options above, display an error message and call the function again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def new_customer():\n",
" response = input(\"We're excited to have you join the DNS family, how can we help you?\")\n",
" if response == \"1\":\n",
" sign_up()\n",
" if response == \"2\":\n",
" home_visit()\n",
" if response == \"3\":\n",
" live_rep(sales)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 5\n",
"\n",
"Now it's time to dive down another level and start defining the next level of functions. Let's start with `television_support()`. **DNS Cable Company** has compiled the three most frequently reported issues and wants those to be surfaced as options in the bot as follows after the prompt \"What is the nature of your problem?\":\n",
"\n",
" [1] I can't access certain channels.\n",
" [2] My picture is blurry.\n",
" [3] I keep losing service.\n",
" \n",
"They also want a fourth catch-all option\n",
"\n",
" [4] Other issues.\n",
" \n",
"Now, for each of these options, they want to give the user the most useful advice they have.\n",
"\n",
"1. If the user enters `1` they want to print the following message and then call the function `did_that_help()` which we will define next. \n",
" Please check the channel lists at DefinitelyNotSinister.com. If the channel you cannot access is there, please contact a live representative.\n",
"2. If the user enters `2` they want to print the following message and then call the function `did_that_help()`\n",
" Try adjusting the antenna above your television set.\n",
"3. If the user enters `3` they want to print the following message and then call the function `did that help()`\n",
" Is it raining outside? If so, wait until it is not raining and then try again.\n",
"4. If the user enters `4` it should direct them immediately to `live_rep(\"support\")`\n",
"5. Just like the other functions, if the user enters something other than these options it should present an error message and call the function again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def television_support():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 6\n",
"\n",
"Next, we will define `internet_support()`, which is will be extremely similar to the function you just defined, `television_support()` except with different possible support issues. Here are the issues that **DNS Cable Company** wants included:\n",
"\n",
" [1] I can't connect to the internet.\n",
" [2] My connection is very slow.\n",
" [3] I can't access certain sites.\n",
" \n",
"Just like for television support, they also want a fourth option for `Other Issues`.\n",
"\n",
"They've highlighted these suggested fixes for each of the issues:\n",
"\n",
"1. If the user selects `1`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Unplug your router, then plug it back in, then give it a good whack, like the Fonz.\n",
"2. If the user selects `2`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Make sure that all cell phones and other peoples computers are not connected to the internet, so that you can have all the bandwidth.\n",
"3. If the user selects `3`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Move to a different region or install a VPN. Some areas block certain sites.\n",
"4. If the user selects `4`, the function should call `live_rep(\"support\")`\n",
"5. Finally, if the user enters something other than the options above, print an error message and recall the function."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def internet_support():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 7\n",
"\n",
"Great work! The last two functioned called the function `did_that_help()`, which we will define now. The purpose of `did_that_help()` is to check if the user was helped by the solution to their problem, and if not, ask them if they'd rather speak to a live representative over the phone or schedule a home visit.\n",
"\n",
"The structure of the function should be as followed:\n",
"1. Ask the user if the solution solved their problem and have them answer Yes or No using `input()`.\n",
"2. If yes, thank them.\n",
"3. If no, prompt them with another question and ask them if they would rather talk to a live representative or schedule a home visit.\n",
"4. If they want to talk to a representative, call `live_rep(\"support\")`\n",
"5. If they want to schedule a home visit, call `home_visit(\"support\")`\n",
"6. Make sure to include error messages for both user responses if they enter a choice not listed above"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def did_that_help():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 8\n",
"Now we've defined all of the initial options of `existing_customer()`, so we'll move onto the options for `new_customer()`, first let's define `sign_up()`.\n",
"\n",
"**DNS Cable Company** is very specific about the greeting they want new customers to see:\n",
"\n",
" Great choice, friend! We're excited to have you join the DNS family! Please select the package you are interested in signing up for.\n",
" [1] Bundle Deal (Internet + Cable)\n",
" [2] Internet\n",
" [3] Cable\n",
" \n",
"Apparently, they want their users to be forced to sign up if they reach this stage! Here's what they want each option to do:\n",
"\n",
"1. If a user selects `1`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Bundle Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"2. If a user selects `2`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Internet Only Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"3. If a user selects `3`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Cable Only Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"4. If a user enters something other than the above choices, print an error message and call `sign_up()` again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def sign_up():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Step 9\n",
"Now we've got an interesting function to define, `home_visit()`. We've called `home_visit()` in three different ways in other functions. In `new_customer()` we call `home_visit()` with no argument, in `internet_support()` and `television_support()` we call `home_visit(\"support\")`, and in `sign_up()` we call `home_visit(\"new install\")`.\n",
"\n",
"This means we want `home_visit()` to take a parameter, which we can call `purpose`, but we want this parameter to be optional with a default value of `\"none\"`.\n",
"\n",
"Now, `home_visit()` should first check `purpose` and then do one of the following:\n",
"1. If `purpose == \"none\"`, we need to determine the purpose of the home visit, so ask the user what the purpose of the home visit is and give them the options\n",
" [1] New service installation.\n",
" [2] Exisitng service repair.\n",
" [3] Location scouting for unserviced region.\n",
" 1. If they select `1` here, call `home_visit(\"new install\")`\n",
" 2. If they select `2` here, call `home_visit(\"support\")`\n",
" 3. If they select `3` here, call `home_visit(\"scout\")`\n",
"\n",
"For all other options, first ask the user\n",
" \n",
" Please enter a date below when you are available for a technician to come to your home and [PURPOSE SPECIFC TEXT HERE].\n",
"\n",
"and save their response to the variable `visit_date`, then respond \n",
" \n",
" Wonderful! A technical will come visit you on [visit_date]. Please be available between the hours of 1:00 am and 11:00 pm.\n",
" \n",
"and return `visit_date`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def home_visit():\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Step 10\n",
"Great work! We have one last function to define! `live_rep()` is called by several different functions, but it always called with one of two arguments, `\"sales\"` or `\"support\"`. All this function needs to do is print a message to the user based on the argument.\n",
"\n",
"1. If the function is called with an argument of `\"sales\"`, print \n",
" Please hold while we connect you with a live sales representative. The wait time will be between two minutes and six hours. We thank you for your patience.\n",
"2. If the function is called with an argument of `\"support\"`, print \n",
" Please hold while we connect you with a live support representative. The wait time will be between two minutes and six hours. We thank you for your patience."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def live_rep(purpose):\n",
" # Replace `pass` with your code\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 11\n",
"\n",
"That's it, your customer service bot should be up and running! Test your code and run `cs_service_bot` and go through some of the choices! Make sure all of your options work and you end up where you expect after each decision."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cs_service_bot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## You're Done!\n",
"\n",
"Great work! Using very simple functions and conditional stables you were able to build a working customer service bot! While it might be a little limited in it's current state, you can always keep adding to it, making each individual function more robust. Some suggestions, try adding in a option to each menu that allows the user to exit without clicking through the entire tree.\n",
"\n",
"You can even build other types of projects using similar techniques! Try building a chat bot that can respond to what you say and ask you questions, or create a text based adventure game where players can make choices to do different actions.\n",
"\n",
"The possibilities are endless! So keep going and happy programming!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

570
Codecadmey Projects/customer_service_bot/customer_service_bot_solution.ipynb

@ -0,0 +1,570 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Off-Platform Project 1: Customer Service Bot\n",
"\n",
"Hi there! In this off-platform project, you will be working as a software engineer for the **Definitely Not Sinister Cable Company**! They have hired you to build for them a bot that can handle basic customer service requests on their website.\n",
"\n",
"First, you will learn a little bit about handling user input, then we will jump right in and start building the functions you need to generate an interactive customer serivce bot.\n",
"\n",
"Let's get started!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Input( )\n",
"\n",
"In Python 3, you can handle basic user text input by using the built-in function `input()`. This is how we will have users interact with your customer service bot. You use `input()` by defining a variable and setting it equal to `input(\"text the user is responding to\")`. \n",
"\n",
"Run the following two code blocks to see how `input()` works."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"name = input(\"What is your name? \")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"print(name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Your response to the question \"What is your name?\" was stored in the variable `name`, which was then printed in the next cell. Great, that's all you need to know for now! Let's get started building the customer service bot!\n",
"\n",
"## Step 1\n",
"\n",
"Before going any further, Go to the 'Cell' drop down at the menu at the top of this notebook and select 'Run All'. This will run all of the cells below so that everything we need to build the customer service bot is ready.\n",
"\n",
"## Step 2\n",
"\n",
"Great, let's get started. First in the cell below, define the function `cs_service_bot`. This will be our main function. Every time a user accesses our support, this function will be called and will guide them through a decision tree to identify their support needs and find them a solution.\n",
"\n",
"1. This function should start by printing:\n",
" Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?\n",
" [1] New Customer\n",
" [2] Existing Customer\n",
" You can store this all in a single string and use the escape character `\\n` to indicate line breaks.\n",
"\n",
"2. Next we want to ask them to choose an option. We are going to do that using `input()`. Make a variable called `response` and have it save the users response using `input()`. You should include text to let the user know how they should make their choice, such as:\n",
" Please enter the number corresponding to your choice: \n",
"3. If the user selects `1` the function should direct them to another function `new_customer()`. We will define this function later.\n",
"4. If the user selects `2` the function should direct them to another function `existing_customer()`. We will define this function later as well.\n",
"5. Finally, if the user enters something other than a `1` or `2` we want our function to print \n",
" Sorry, we didn't understand your selection.\n",
" and then run `cs_serivce_bot` again to let them make another choice."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def cs_service_bot():\n",
" print(\"Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer? \\n [1] New Customer \\n [2] Existing Customer\")\n",
" response_one = input(\"Please enter the number corresponding to your choice: \")\n",
" if response_one == \"1\":\n",
" new_customer()\n",
" elif response_one == \"2\":\n",
" existing_customer()\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" cs_service_bot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Great Job! Run `cs_service_bot()` in the cell below and see how it works."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Cool! We have the initial skeleton done, now we have to define `new_customer()` and `existing_customer()`.By breaking up our bot into a bunch of smaller functions we can build each piece incrementally and check our progress as we slowly build a fully functioning product.\n",
"\n",
"## Step 3\n",
"Let's start with `existing_customer()`. The options **DNS Cable Company** wants users to be able to select are \n",
"\n",
" [1] Television Support\n",
" [2] Internet Support\n",
" [3] Speak to a support representative. \n",
"\n",
"Have `existing_customer()` print \"What kind of support do you need?\" and then these three options. Remember, use the escape character `\\n` in strings for line breaks. Use `input()` in the same way as the previous function to record the users choice.\n",
"\n",
"1. If they select `1`, call the function `television_support()` which will we define later.\n",
"2. If they select `2`, call the function `internet_support()` which we will also define later.\n",
"3. If they select `3`, call the function `live_rep()` with the argument `\"support\"`. We'll use this argument to indicate what type of live representative the user will talk to. We will define the function later.\n",
"4. Finally, just like the `cs_service_bot()` function, if the user enters something other than the three options above, have the function print\n",
" Sorry, we didn't understand your selection.\n",
"and call itself to let them try again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def existing_customer():\n",
" print(\"What kind of support do you need? \\n [1] Television Support \\n [2] Internet Support \\n [3] Speak to a support representative\")\n",
" response = input(\"Please enter the number corresponding to your choice: \")\n",
" if response == \"1\":\n",
" television_support()\n",
" elif response == \"2\":\n",
" internet_support()\n",
" elif response == \"3\":\n",
" live_rep(\"support\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" existing_customer()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4\n",
"You can see that we've introduced a whole new slew of functions as options of `existing_customer()`, and we'll define those soon but first let's define `new_customer()`.\n",
"\n",
"The options the **DNS Cable Company** wants for `new_customer()` are \n",
" \n",
" [1] Sign up for service.\n",
" [2] Schedule a home visit.\n",
" [3] Speak to a sales representative.\n",
" \n",
"They also want this function to greet their potential new customers with the phrase \"We're excited to have you join the DNS family, how can we help you?\" A little cheesy if you ask me but hey, the client is always right.\n",
"\n",
"1. If the user selects `1`, call the function `sign_up()`.\n",
"2. If the user selects `2`, call the function `home_visit()`.\n",
"3. If the user selects `3`, call the function `live_rep()` with the argument `\"sales\"` so the program directs them to the correct live representative.\n",
"4. Finally, like the other functions, if the user sumbits something other than the options above, display an error message and call the function again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def new_customer():\n",
" print(\"We're excited to have you join the DNS family, how can we help you? [1] Sign up for service. \\n [2] Schedule a home visit. \\n [3] Speak to a sales representative.\")\n",
" response_two = input(\"Please enter the number corresponding to your choice: \")\n",
" if response_two == \"1\":\n",
" sign_up()\n",
" elif response_two == \"2\":\n",
" home_visit()\n",
" elif response_two == \"3\":\n",
" live_rep(\"sales\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" new_customer()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 5\n",
"\n",
"Now it's time to dive down another level and start defining the next level of functions. Let's start with `television_support()`. **DNS Cable Company** has compiled the three most frequently reported issues and wants those to be surfaced as options in the bot as follows after the prompt \"What is the nature of your problem?\":\n",
"\n",
" [1] I can't access certain channels.\n",
" [2] My picture is blurry.\n",
" [3] I keep losing service.\n",
" \n",
"They also want a fourth catch-all option\n",
"\n",
" [4] Other issues.\n",
" \n",
"Now, for each of these options, they want to give the user the most useful advice they have.\n",
"\n",
"1. If the user enters `1` they want to print the following message and then call the function `did_that_help()` which we will define next. \n",
" Please check the channel lists at DefinitelyNotSinister.com. If the channel you cannot access is there, please contact a live representative.\n",
"2. If the user enters `2` they want to print the following message and then call the function `did_that_help()`\n",
" Try adjusting the antenna above your television set.\n",
"3. If the user enters `3` they want to print the following message and then call the function `did that help()`\n",
" Is it raining outside? If so, wait until it is not raining and then try again.\n",
"4. If the user enters `4` it should direct them immediately to `live_rep(\"support\")`\n",
"5. Just like the other functions, if the user enters something other than these options it should present an error message and call the function again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def television_support():\n",
" print(\"What is the nature of your problem? \\n [1] I can't access certain channels. \\n [2] My picture is blurry. \\n [3] I keep losing service. \\n [4] Other issue.\")\n",
" response = input(\"Please enter the number corresponding to your choice: \")\n",
" if response == \"1\":\n",
" print(\"Please check the channel lists at DefinitelyNotSinister.com. If the channel you cannot access is there, please contact a live representative.\")\n",
" did_that_help()\n",
" elif response == \"2\":\n",
" print(\"Try adjusting the antenna above your television set.\")\n",
" did_that_help()\n",
" elif response == \"3\":\n",
" print(\"Is it raining outside? If so, wait until it is not raining and then try again.\")\n",
" did_that_help()\n",
" elif response == \"4\":\n",
" live_rep(\"support\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" television_support()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 6\n",
"\n",
"Next, we will define `internet_support()`, which is will be extremely similar to the function you just defined, `television_support()` except with different possible support issues. Here are the issues that **DNS Cable Company** wants included:\n",
"\n",
" [1] I can't connect to the internet.\n",
" [2] My connection is very slow.\n",
" [3] I can't access certain sites.\n",
" \n",
"Just like for television support, they also want a fourth option for `Other Issues`.\n",
"\n",
"They've highlighted these suggested fixes for each of the issues:\n",
"\n",
"1. If the user selects `1`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Unplug your router, then plug it back in, then give it a good whack, like the Fonz.\n",
"2. If the user selects `2`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Make sure that all cell phones and other peoples computers are not connected to the internet, so that you can have all the bandwidth.\n",
"3. If the user selects `3`, the function should recommend the following solution and then call `did_that_help()`.\n",
" Move to a different region or install a VPN. Some areas block certain sites.\n",
"4. If the user selects `4`, the function should call `live_rep(\"support\")`\n",
"5. Finally, if the user enters something other than the options above, print an error message and recall the function."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def internet_support():\n",
" print(\"What is the nature of your problem? \\n [1] I can't connect to the internet. \\n [2] My connection is very slow. \\n [3] I can't access certain sites. \\n [4] Other issue.\")\n",
" response = input(\"Please enter the number corresponding to your choice: \")\n",
" if response == \"1\":\n",
" print(\"Unplug your router, then plug it back in, then give it a good whack, like the Fonz.\")\n",
" did_that_help()\n",
" elif response == \"2\":\n",
" print(\"Make sure that all cell phones and other peoples computers are not connected to the internet, so that you can have all the bandwidth.\")\n",
" did_that_help()\n",
" elif response == \"3\":\n",
" print(\"Move to a different region or install a VPN. Some areas block certain sites.\")\n",
" did_that_help()\n",
" elif response == \"4\":\n",
" live_rep(\"support\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" internet_support()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 7\n",
"\n",
"Great work! The last two functioned called the function `did_that_help()`, which we will define now. The purpose of `did_that_help()` is to check if the user was helped by the solution to their problem, and if not, ask them if they'd rather speak to a live representative over the phone or schedule a home visit.\n",
"\n",
"The structure of the function should be as followed:\n",
"1. Ask the user if the solution solved their problem and have them answer Yes or No using `input()`.\n",
"2. If yes, thank them.\n",
"3. If no, prompt them with another question and ask them if they would rather talk to a live representative or schedule a home visit.\n",
"4. If they want to talk to a representative, call `live_rep(\"support\")`\n",
"5. If they want to schedule a home visit, call `home_visit(\"support\")`\n",
"6. Make sure to include error messages for both user responses if they enter a choice not listed above"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def did_that_help():\n",
" print(\"Did that solve the problem? \\n [1] Yes \\n [2] No\")\n",
" response = input(\"Please enter the number corresponding to your choice: \")\n",
" if response == \"1\":\n",
" print(\"Great! Have a wonderful day.\")\n",
" elif response == \"2\":\n",
" print(\"We're sorry. Would you like to talk to a live representative or schedule a home visit to address your problem? \\n [1] Live Representative [2] Home Visit\")\n",
" response_two = input(\"Please enter the number corresponding to your choice: \")\n",
" if response_two == \"1\":\n",
" live_rep(\"support\")\n",
" elif response_two == \"2\":\n",
" home_visit(\"support\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" did_that_help()\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" did_that_help()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 8\n",
"Now we've defined all of the initial options of `existing_customer()`, so we'll move onto the options for `new_customer()`, first let's define `sign_up()`.\n",
"\n",
"**DNS Cable Company** is very specific about the greeting they want new customers to see:\n",
"\n",
" Great choice, friend! We're excited to have you join the DNS family! Please select the package you are interested in signing up for.\n",
" [1] Bundle Deal (Internet + Cable)\n",
" [2] Internet\n",
" [3] Cable\n",
" \n",
"Apparently, they want their users to be forced to sign up if they reach this stage! Here's what they want each option to do:\n",
"\n",
"1. If a user selects `1`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Bundle Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"2. If a user selects `2`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Internet Only Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"3. If a user selects `3`, they want to print the following message and then call `home_visit(\"new install\")`\n",
" You've selected the Cable Only Package! Please schedule a home visit and our technician will come and set up your new service.\n",
"4. If a user enters something other than the above choices, print an error message and call `sign_up()` again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def sign_up():\n",
" print(\"Great choice, friend! We're excited to have you join the DNS family! Please select the package you are interested in signing up for. \\n [1] Bundle Deal (Internet + Cable) \\n [2] Internet \\n [3] Cable\")\n",
" response = input(\"Please enter the number corresponding to your choice: \")\n",
" if response == \"1\":\n",
" print(\"You've selected the Bundle Package! Please schedule a home visit and our technician will come and set up your new service.\")\n",
" home_visit(\"new install\")\n",
" elif response == \"2\":\n",
" print(\"You've selected the Internet Only Package! Please schedule a home visit and our technician will come and set up your new service.\")\n",
" home_visit(\"new install\")\n",
" elif response == \"3\":\n",
" print(\"You've selected the Cable Only Package! Please schedule a home visit and our technician will come and set up your new service.\")\n",
" home_visit(\"new install\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" sign_up() "
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Step 9\n",
"Now we've got an interesting function to define, `home_visit()`. We've called `home_visit()` in three different ways in other functions. In `new_customer()` we call `home_visit()` with no argument, in `internet_support()` and `television_support()` we call `home_visit(\"support\")`, and in `sign_up()` we call `home_visit(\"new install\")`.\n",
"\n",
"This means we want `home_visit()` to take a parameter, which we can call `purpose`, but we want this parameter to be optional with a default value of `\"none\"`.\n",
"\n",
"Now, `home_visit()` should first check `purpose` and then do one of the following:\n",
"1. If `purpose == \"none\"`, we need to determine the purpose of the home visit, so ask the user what the purpose of the home visit is and give them the options\n",
" [1] New service installation.\n",
" [2] Exisitng service repair.\n",
" [3] Location scouting for unserviced region.\n",
" 1. If they select `1` here, call `home_visit(\"new install\")`\n",
" 2. If they select `2` here, call `home_visit(\"support\")`\n",
" 3. If they select `3` here, call `home_visit(\"scout\")`\n",
"\n",
"For all other options, first ask the user\n",
" \n",
" Please enter a date below when you are available for a technician to come to your home and [PURPOSE SPECIFC TEXT HERE].\n",
"\n",
"and save their response to the variable `visit_date`, then respond \n",
" \n",
" Wonderful! A technical will come visit you on [visit_date]. Please be available between the hours of 1:00 am and 11:00 pm.\n",
" \n",
"and return `visit_date`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def home_visit(purpose=\"none\"):\n",
" if purpose == \"none\":\n",
" print(\"What is the purpose of your home visit? \\n [1] New service installation. \\n [2] Existing service repair. \\n [3] Location scouting for unserviced regions.\")\n",
" response = input(\"Please enter the number corresponding to your choice: \")\n",
" if response == \"1\":\n",
" home_visit(\"new install\")\n",
" elif response == \"2\":\n",
" home_visit(\"support\")\n",
" elif response == \"3\":\n",
" home_visit(\"scout\")\n",
" else:\n",
" print(\"Sorry, we didn't understand your selection.\")\n",
" home_visit()\n",
" if purpose == \"new install\":\n",
" print(\"Please enter a date below when you are available for a technician to come to your home and install your new service.\")\n",
" visit_date = input(\"Date:\")\n",
" print(\"Wonderful! A technical will come visit you on \" + visit_date + \". Please be available between the hours of 1:00 am and 11:00 pm.\" )\n",
" return visit_date\n",
" if purpose == \"support\":\n",
" print(\"Please enter a date below when you are available for a technician to come and inspect the problem:\")\n",
" visit_date = input(\"Date:\")\n",
" print(\"Wonderful! A technical will come visit you on \" + visit_date + \". Please be available between the hours of 1:00 am and 11:00 pm.\" )\n",
" return visit_date\n",
" if purpose == \"scout\":\n",
" print(\"Please enter a date below when you are available for a technician to come scout your region for expansion:\")\n",
" visit_date = input(\"Date:\")\n",
" print(\"Wonderful! A technical will come visit you on \" + visit_date + \". Please be available between the hours of 1:00 am and 11:00 pm.\" )\n",
" return visit_date"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Step 10\n",
"Great work! We have one last function to define! `live_rep()` is called by several different functions, but it always called with one of two arguments, `\"sales\"` or `\"support\"`. All this function needs to do is print a message to the user based on the argument.\n",
"\n",
"1. If the function is called with an argument of `\"sales\"`, print \n",
" Please hold while we connect you with a live sales representative. The wait time will be between two minutes and six hours. We thank you for your patience.\n",
"2. If the function is called with an argument of `\"support\"`, print \n",
" Please hold while we connect you with a live sales representative. The wait time will be between two minutes and six hours. We thank you for your patience."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def live_rep(purpose):\n",
" if purpose == \"sales\":\n",
" print(\"Please hold while we connect you with a live sales representative. The wait time will be between two minutes and six hours. We thank you for your patience.\")\n",
" if purpose == \"support\":\n",
" print(\"Please hold while we connect you with a live sales representative. The wait time will be between two minutes and six hours. We thank you for your patience.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 11\n",
"\n",
"That's it, your customer service bot should be up and running! Test your code and run `cs_service_bot` and go through some of the choices! Make sure all of your options work and you end up where you expect after each decision."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"cs_service_bot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## You're Done!\n",
"\n",
"Great work! Using very simple functions and conditional stables you were able to build a working customer service bot! While it might be a little limited in it's current state, you can always keep adding to it, making each individual function more robust. Some suggestions, try adding in a option to each menu that allows the user to exit without clicking through the entire tree.\n",
"\n",
"You can even build other types of projects using similar techniques! Try building a chat bot that can respond to what you say and ask you questions, or create a text based adventure game where players can make choices to do different actions.\n",
"\n",
"The possibilities are endless! So keep going and happy programming!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

25
Codecadmey Projects/ex7_ch5?.py

@ -0,0 +1,25 @@
# Write your max_num function here:
def max_num(num1, num2, num3):
if num1 > num2 and num1 > num3:
return num1
elif num2 > num1 and num2 > num3:
return num2
elif num3 > num1 and num3 > num2:
return num3
elif num2 > num3 and num1 == num2:
return "It's a tie!"
elif num3 > num2 and num3 == num1:
return "It's a tie!"
elif num3 > num1 and num2 == num3:
return "It's a tie!"
# Uncomment these function calls to test your max_num function:
print(max_num(-10, 0, 10))
# should print 10
print(max_num(-10, 5, -30))
# should print 5
print(max_num(-5, -10, -10))
# should print -5
print(max_num(2, 3, 3))
# should print "It's a tie!"
Loading…
Cancel
Save