0

im trying to get myself into Python. And right in the beginning i am encountering this problem. What am i doing wrong? Is there something wrong with my setup? Pls help

I'm running Python 3.8.2 on macos using vscode.

Code:

name = input("Name: ")
print("hello, " + name + "!")

Error:

bashkim@Bashkims-MBP test % python name.py
Name: Bashkim
Traceback (most recent call last):
  File "name.py", line 1, in <module>
    name = input("Name: ")
  File "<string>", line 1, in <module>
NameError: name 'Bashkim' is not defined

Tried also following:

Code::

name = input()
print(f"hello, {name}!")

Error:

bashkim@Bashkims-MBP test % python name.py
  File "name.py", line 2
    print(f"hello, {name}!")
                          ^
SyntaxError: invalid syntax

enter image description here

Bashkim
  • 9
  • 1
  • 5
    Briefly: no, you're not using Python 3.8.2; you're using Python 2. – TigerhawkT3 Dec 20 '20 at 22:43
  • @TigerhawkT3 Shouldn't the first piece of code work for Python 2? – M-Chen-3 Dec 20 '20 at 22:43
  • 2
    @M-Chen-3 - No, it will produce the displayed error. It's trying to evaluate the user-entered string as Python code. – TigerhawkT3 Dec 20 '20 at 22:44
  • @M-Chen-3, no. [`input()` tries to `eval` its argument in Python 2](https://docs.python.org/2.7/library/functions.html#input). You'd want to use `raw_input()` instead. – Chris Dec 20 '20 at 22:44
  • @M-Chen-3 no. In Python 2, you'd need to use `raw_input`, not `input`. – Mureinik Dec 20 '20 at 22:44
  • Thats strange i clearly selected v3.8.2 as seen in this screenshot... what am i doing wrong here -.- thanks guys https://i.stack.imgur.com/NOP6U.png – Bashkim Dec 21 '20 at 13:04
  • okay i now found out that i need to terminal run: "python3 name.py" – Bashkim Dec 21 '20 at 13:11

0 Answers0