Problem with in ex 50 [Solved]

I have just started to write the first code for ex 50.

File "", line 7
    return f'Hello, {greeting}!'
SyntaxError: invalid syntax

A got an error at the last ( ’ ) in line 7

As far as I can se my code is identical to the code in the book “learn-python3-the-hard-way-jul-4-2017.pdf”

Here is my code:

from flask import Flask
app = Flask(__name__)

def hello_world():
    greeting = 'World'
    return f'Hello, {greeting}!'
if __name__ == "__main__":

Please help me to see why I got this error.

What version of Python are you using? It looks like you’re using 3.5 or 2.

I ran exactly the same code, and I didn’t get an error. Yeah, it looks like your python version isn’t compatible with formatting strings using f’’. I actually haven’t seen that style of string formatting before.


I have version 3.5.2 when using virtual enviorment.
How about my code? Did I miss anything? Or did some “hard to find” miss spelling?
I have written it by myself. There is no copy, paste.
I use nano for writing code.
The only issues with the editor so far is me using it to type in bugs her and there :slight_smile: (but I feel some improvement in finding them).

I am using Linux as OS (Ubuntu 16.04) on a laptop I bought this summer. So I should not have any performance issues.

No, the code looks good so it’s your python version. You need version 3.6, and actually if you’re having that problem at this exercise then I’m guessing you’ve skipped ahead as you would have ran into this very early on.


Thanks again for help.
Upgrading to 3.6 was the solution.
I also had to install flask for python 3. There was a error message that told me there was no module named ‘flask’ After upgrading flask I got “my website” up and running. :slight_smile:

I haven’t skipped any exercises yet (but i have to admit I did not do all study drills in them :roll_eyes: ).
I changed to follow the book for python 3 when starting this exercise. I think thats why I have not had any of this problem before.

Again. Thanks a lot for support.