0

I get invalid syntax error when I try to iterate over a list of names saved in names.txt file. Here's the syntax

names = []

with open("names.txt") as file:
    for line in file:
        names.append(line.rstrip().capitalize())

for name in sorted(names, reverse=True):
    print(f"hello, {name}")

The error I'm getting looks like:

$ python name_read.py
  File "name_read.py", line 8
    print(f"hello, {name}")
                         ^
SyntaxError: invalid syntax

Could you please help? Thanks!

Getu
  • 1
  • 1

0 Answers0