-2
Good morning,
I’m starting a Python course by Cs50, but I don’t understand what happened to the code I wrote.
name = input("Name: ")
print("Hello, " + name)
You can see that it is simple and yet this error is shown in the terminal:
Name: alberty
Traceback (most recent call last):
File "name.py", line 1, in <module>
name = input("Name: ")
File "<string>", line 1, in <module>
NameError: name 'alberty' is not defined
What I must do, is some configuration or error?
PS: I also did otherwise:
print(f"Hello, {name}")
And the result was this:
File "name.py", line 2
print(f"Hello, {name}")
^
SyntaxError: invalid syntax
You’re running the code with
Python 2
and this code isPython 3
. To use Python 2, modifyinput
forraw_input
in the first part. Note: f-strings can only be used in Python 3– Paulo Marques
@Paulomarques Just to be exact, f-strings is from Python 3.6 :-)
– hkotsubo