In this chapter, you learned several ways to find and fix problems in your code. You might conduct a code review, add program trace statements, or even use a debugger to step through the program line-by-line.

We have created a program called "ChatBot" that should have a short, interactive conversation with the user. Unfortunately, we didn't get all of the code completely right, and there are several errors that we need help finding and fixing. Your job is to make the ChatBot code work exactly according to the program requirements.

ChatBot should ask for the user's name, then continue with a couple of other questions. The third question and response will depend on the user's answer to the second question.

Specific Questions and Outputs
ChatBot's specific questions and responses are described below. There are 8 possible paths through the code, depending on the user's answers to the three questions.

Question and Response #1

ChatBot should first ask the following question and get store the response as a string in the name variable:

"What is your name?"

ChatBot should then print

"Hi <name>, nice to meet you. I am Chatbot-1024."

Question #2

ChatBot should next ask the following question and store the input() response as a string in the sport variable:

"What is your favorite sport?"

ChatBot will then check the sport variable with a series of if / elif statements to see if it equals "football", "baseball" or "basketball".

Question and Response #3

If the sport answer is "football", ChatBot will then use input() to ask Question #3 and store the response as an integer in the yards variable:

"I like football too. Can you tell me the length of a football field in yards?"

Response #3 is printed by checking the user's yards answer:

If the yards is less than 100, ChatBot should print "No, too short."

ElIf the yards is greater than 100, ChatBot should print "No, too long."

Else, ChatBot should print "That's right!"

Elif the sport answer is "baseball", ChatBot will then use input() to ask Question #3 and store the response as an integer in the strikes variable:

"I play baseball every summer. How many 'strikes' does it take to get a batter out?"

Response #3 is printed by checking the user's strikes answer:

If the strikes is equal to 3, ChatBot should print "Yes, 1, 2, 3 strikes you're out..."

Else, ChatBot should print "Actually, 3 strikes will get a batter out."

Elif the sport answer is "basketball", ChatBot will then use input() to ask Question #3 and store the response as a string in the team variable:

"The Harlem Globetrotters are the best. Do you know the name of the team they always beat?"

Response #3 is printed by checking the user's team answer:

If the team is equal to "Washington Generals", ChatBot should print "Yes, those Generals can never catch a break."

Else, ChatBot should print "I think it's the Washington Generals."

Else

ChatBot should print "That sounds cool; I've never played <sport>."

Starting Code
Here is the starting ChatBot program. If you are working offline, you can copy and paste it into a "ChatBot.py" source file that you create. But if you are working with CompuScholar's auto-graded system, you will find this code waiting for you when you click on the activity link in the course interface.
Your job is to find and fix all of the ChatBot errors, so all 8 test cases below will pass. You can use any combination of code review, Python reference documents, program tracing, or the debugger that you like to get the job done.

Hint 1: There are 2 syntax errors, 2 run-time logical errors, and 1 run-time exception that you need to fix.

Hint 2: Don't forget to fix all syntax errors first before trying to use the Python debugger.

Test #1 - Input: Name = Matt, sport = "football", length = 100
What is your name? Matt
Hi Matt, nice to meet you. I am Chatbot-1024.
What is your favorite sport? football
I like football too. Can you tell me the length of a football field in yards? 100
That's right!
Great chatting with you.
Test #2 - Input: Name = Matt, sport = "football", length = 75
What is your name? Matt
Hi Matt, nice to meet you. I am Chatbot-1024.
What is your favorite sport? football
I like football too. Can you tell me the length of a football field in yards? 75
No, too short.
Great chatting with you.
Test #3 - Input: Name = Matt, sport = "football", length = 125
What is your name? Matt
Hi Matt, nice to meet you. I am Chatbot-1024.
What is your favorite sport? football
I like football too. Can you tell me the length of a football field in yards? 125
No, too long.
Great chatting with you.
Test #4 - Input: Name = Monica, sport = "baseball", strikes = 3
What is your name? Monica
Hi Monica, nice to meet you. I am Chatbot-1024.
What is your favorite sport? baseball
I play baseball every summer. How many 'strikes' does it take to get a batter out? 3
Yes, 1, 2, 3 strikes you're out...
Great chatting with you.
Test #5 - Input: Name = Monica, sport = "baseball", strikes = 4
What is your name? Monica
Hi Monica, nice to meet you. I am Chatbot-1024.
What is your favorite sport? baseball
I play baseball every summer. How many 'strikes' does it take to get a batter out? 4
Actually, 3 strikes will get a batter out.
Great chatting with you.
Test #6 - Input: Name = Camila, sport = "basketball", team = "Washington Generals"
What is your name? Camila
Hi Camila, nice to meet you. I am Chatbot-1024.
What is your favorite sport? basketball
The Harlem Globetrotters are the best. Do you know the name of the team they always beat? Washington Generals
Yes, those Generals can never catch a break.
Great chatting with you.
Test #7 - Input: Name = Camila, sport = "basketball", team = "Patsies"
What is your name? Camila
Hi Camila, nice to meet you. I am Chatbot-1024.
What is your favorite sport? basketball
The Harlem Globetrotters are the best. Do you know the name of the team they always beat? Patsies
I think it's the Washington Generals.
Great chatting with you.
Test #8 - Input: Name = Frederick, sport = "lacrosse"
What is your name? Frederick
Hi Frederick, nice to meet you. I am Chatbot-1024.
What is your favorite sport? lacrosse
That sounds cool; I've never played lacrosse.
Great chatting with you.
When your program is complete and tested, submit it for grading!

# Student Name

# Start the Conversation
name = input("What is your name? ")
print("Hi", + name + ", nice to meet you. I am Chatbot-1024.")

# ask about a favorite sport
sport = input("What is your favorite sport? ")
if sport == "football":
# respond to football with a question
yards = int(input("I like football too. Can you tell me the length of a football field in yards? "))
# verify and comment on the answer
if yards < 100:
print("No, too short.")
elif yards > 100:
print("No, too long.")
else:
print("That's right!")

elif sport == "baseball":
# respond to baseball with a question
strikes = int(input("I play baseball every summer. How many 'strikes' does it take to get a batter out? "))
# verify and comment on the answer
if strikes == 3:
print("Yes, 1, 2, 3 strikes you're out...")
else:
print("Actually, 3 strikes will get a batter out.")

elif sport == "basketball":
# respond to basketball with a question
team = input("The Harlem Globetrotters are the best. Do you know the name of the team they always beat? ")
# verify and comment on the answer (check for either version with or without capitals)
if team == "Washington Generals":
print("Yes, those Generals can never catch a break.")
else:
print("I think it's the Washington Generals.")

else:
# user entered a sport we don't recognize, so just display a standard comment
print("That sounds cool; I've never played " + sport + ".")

print("Great chatting with you.")

# Student Name

# Start the Conversation
name = input("What is your name? ")
print("Hi " + name + ", nice to meet you. I am Chatbot-1024.")

# ask about a favorite sport
sport = input("What is your favorite sport? ")
if sport == "football":
# respond to football with a question
yards = int(input("I like football too. Can you tell me the length of a football field in yards? "))
# verify and comment on the answer
if yards < 100:
print("No, too short.")
elif yards > 100:
print("No, too long.")
else:
print("That's right!")

elif sport == "baseball":
# respond to baseball with a question
strikes = int(input("I play baseball every summer. How many 'strikes' does it take to get a batter out? "))
# verify and comment on the answer
if strikes == 3:
print("Yes, 1, 2, 3 strikes you're out...")
else:
print("Actually, 3 strikes will get a batter out.")

elif sport == "basketball":
# respond to basketball with a question
team = input("The Harlem Globetrotters are the best. Do you know the name of the team they always beat? ")
# verify and comment on the answer (check for either version with or without capitals)
if team == "Washington Generals":
print("Yes, those Generals can never catch a break.")
else:
print("I think it's the Washington Generals.")

else:
# user entered a sport we don't recognize, so just display a standard comment
print("That sounds cool; I've never played " + sport + ".")

print("Great chatting with you.")