0

I have recently started learning programming by watching CS50 course. I am currently on the introduction of Python. Everything was done by me in accordance to that video-course. By writing simple code I get an issue unlike my lecturer does.

Here it is:

answer = input("What's your name?")
print(f"hello, {answer}")

Issue I have got:

File "hi.py", line 2
    print(f"hello, {answer}")
                           ^
SyntaxError: invalid syntax

I would be sincerely grateful for your answer!

Chris
  • 112,704
  • 77
  • 249
  • 231
Nazar
  • 1
  • 1
  • Please format the code - select it and type `ctrl-k`. .. [Formatting help](https://stackoverflow.com/editing-help)... [Formatting sandbox](https://meta.stackexchange.com/questions/3122/formatting-sandbox) – wwii Apr 24 '22 at 18:48
  • 3
    What version of Python are you using? It's probably a version that predates f-strings, which were introduced in Python 3.6 if memory serves. – Chris Apr 24 '22 at 18:48
  • I am using Python 2.7.16 – Nazar Apr 24 '22 at 18:51
  • 3
    Python 2 has been end-of-life for over two years. I strongly suggest you install Python 3. The current release is Python 3.10. – Chris Apr 24 '22 at 18:51
  • I am grateful for support, Chris! – Nazar Apr 24 '22 at 18:54

1 Answers1

-1

hello you can't use the print function in the Variable so the right way to write this is

answer = input("What's your name?") 
print(f"hello, {answer}")

Chris
  • 112,704
  • 77
  • 249
  • 231
Rabee
  • 1
  • 1
  • ...isn't this exactly the same code as in the question? – Chris Apr 24 '22 at 18:58
  • I have just copied, inserted the code suggested and it still does not work. So I am up to download the newer version of Python. – Nazar Apr 24 '22 at 19:01