Your computer is automatically generating curvy quotes by default, Bruno. Find out where they’re coming from and disable that “feature” or it will cause you constant headaches when programming. The “print” in the quote above has curvy quotes and your first code sample also has them in the line name = "John"
.
If you like the curvy quotes and need/want to keep them…
PyCharm is evidently following the curvy quotes setting. You might try VS Code to see if it produces “typewriter” quotes in the code editor. You could also try Notepad++ but that’s less ideal than the first two. (VS Code is great; I changed from PyCharm quickly after trying VS Code.)
Glad you got the help you were looking for, Bruno. I can’t say that I would have noticed a missing ‘print’ function (and it doesn’t look like print()
was actually your problem), but I can say that the default message body font makes errors MUCH harder to see. You’ll do everyone a big favor–especially yourself–if you fence your posted code with backtics like this:
```python
<code goes here>
```
P.S. The fstring code ran fine without the print
. I haven’t yet read the docs.python.org on fstrings but this post at RealPython shows the same syntax you used in your posted code. That is, it also omits the print
instruction.
If you do use print
, you need to enclose your print()
arguments in parentheses as shown below.
>>> n1 = input("First number:")
>>> n2 = input("Second number:")
f"The result is {n1}+{n2}"
'The result is 1+2'
>>> print (f"The result is {n1}+{n2}")
The result is 1+2
>>> print f"The result is {n1}+{n2}"
File <Javascript undefined>, line 1
print f"The result is {n1}+{n2}"
^
SyntaxError: missing parenthesis in call to 'print'
>>>
Notice the caret ( ^ ⟩. It points to exactly where the error message was triggered*. As you continue your Python journey, get good at reading the error messages and you’ll be able to work problems out quicker (and without having to wait for an answer on a forum ).
* The error message refers to Javascript because I ran the code in Brython, a Python interpreter written on Javascript so that it runs in a browser.
If you’d like some simple practice, run your name = “John”
line as-is with the curly brackets and read the full error code.