I am new could someone help me fix my problem.
MY code:
print('Robot: Hi my name is "Robot" Your Emotional Helping Hand "EHH" for short.')
print("Robot: How is your day? Good or Bad?")
Feeling=input("You: ")
if Feeling == "Bad":
print("Robot: I am sorry to hear that.")
print("Robot: How can I help? ")
print("-------------------------------------------")
print("If Option 1: GO AWAY! Type: 1 ")
print("If Option 2: I could real use a friend to talk to. Type: 2 ")
print("Pick Only One")
print("-------------------------------------------")
Options = input("Option: ")
elif Feeling == "Good":
print("Robot: Good Have a nice day:) shuting down")
if Options == "1":
print("You: GO AWAY!")
print("Robot: ok:( shuting down")
elif Options == "2":
print("You: I could real use a friend to talk to.")
print("Robot: Ok, What do you want to talk about? ")
The Problem:
Robot: Hi my name is "Robot" Your Emotional Helping Hand "EHH" for short.
Robot: How is your day? Good or Bad?
You: Good
Robot: Good Have a nice day:) shuting down
Traceback (most recent call last):
File "main.py", line 16, in <module>
if Options == "1":
NameError: name 'Options' is not defined
The issue is that you need the option conditions inside the first if statement.
Here is the fixed code:
print('Robot: Hi my name is "Robot" Your Emotional Helping Hand "EHH" for short.')
print("Robot: How is your day? Good or Bad?")
Feeling = input("You: ")
if Feeling == "Bad":
print("Robot: I am sorry to hear that.")
print("Robot: How can I help? ")
print("-------------------------------------------")
print("If Option 1: GO AWAY! Type: 1 ")
print("If Option 2: I could real use a friend to talk to. Type: 2 ")
print("Pick Only One")
print("-------------------------------------------")
Options = input("Option: ")
if Options == "1":
print("You: GO AWAY!")
print("Robot: ok:( shuting down")
elif Options == "2":
print("You: I could real use a friend to talk to.")
print("Robot: Ok, What do you want to talk about? ")
elif Feeling == "Good":
print("Robot: Good Have a nice day:) shuting down")
Can you link a repl? It'll be easier to find the problem. Also with elif Feeling == "Good":
, that won't work as you can't have an elif
statement hanging on its own, you'll need an if
statement before that.
It's kinda hard to read because of the improper indenting, but if the
Options = input("...")
line is in the scope of an if and you're trying to access it outside, there's going to be an errorhow to fix:
add a global before "Options"