Ich bin immer noch nicht zu der Schlussfolgerung gekommen, warum das folgende Stück Python in IDLE funktioniert, aber nicht im Terminal. Jede Hilfe wäre willkommen.Python läuft in IDLE aber nicht Terminal?
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!")
Der Fehler
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
Ihr Terminal verwendet wahrscheinlich Python 2, weshalb bei der Verwendung von 'input' ein' NameError' ausgelöst wird. Versuchen Sie mit 'raw_input' zu laufen, dem Python 2 Äquivalent zu Python 3' input.' In Python 2 ist 'input' das Äquivalent zu' eval (input()) 'in Python 3 –
@ juanpa.arrivillaga hat wahrscheinlich die beste Schätzung . Ich habe das nur in Python 3 ausgeführt und es schien zu funktionieren. Geben Sie 'python --version' auf dem Terminal ein und prüfen Sie, ob 2. [etwas] statt 3. [etwas] ausgegeben wird. – Cody