LuckyMuffin LuckyMuffin - 3 months ago 16
Python Question

Python running in IDLE but not terminal?

upon looking around a bit I have still not come to the conclusion as to why the following piece of python works in IDLE but not terminal. Any help would be appreciated.

print("Hello User!")

request_list = ['']

while True:
greeting = input('')

if greeting.lower() == "hello":
print("Who is this?")
print("Welcome back " + input() +", what can I do for you?")
break

elif greeting.lower() != "hello":
print("Show some manners!")


The error

Traceback (most recent call last):
File "courtney.py", line 23, in <module>
greeting = input('')
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined

Answer

you are running python3 IDLE and the terminal is set to python2.

In your computer's environmental variables, you want to change the path to the location of your Python3 installation instead of the python 2.

Take a look at the picture, the one you want to change is PATH

Environmental Variables

If you dont want to change your environmental variables so that your terminal stays using python2, then you have to change your input and print statements.

the code below is the implementation of your code in python 2.7:

print "Hello User!" 

request_list = ['']

while True:
    greeting = raw_input("What is your name? ")

    if greeting.lower() == "hello":
        print "Who is this?"
        print "Welcome back " + greeting +", what can I do for you?"
        break

    elif greeting.lower() != "hello":
        print "Show some manners!"
Comments