1

Very new to coding, so I could be missing something basic. On a lesson about the print function, we learned this to be a valid method:

today_price = 1100
yesterday_price = 1000
print(f"Today's price: {today_price}, yesterday's price: {yesterday_price}")

When I put that in however, I recieve 'SyntaxError: Invalid Syntax' with and arrow pointed to my last double quote.

Any ideas what this could be? This is the example given in the lesson and is copied and pasted from class notes.

Prune
  • 76,765
  • 14
  • 60
  • 81
  • 7
    What is the python version you are using? If you are using python < 3.6, then it won't work. – ywbaek Mar 25 '20 at 00:51
  • This works nicely in Python 3.6.8 – Prune Mar 25 '20 at 00:53
  • 1
    The f-string syntax was introduced in recent versions of Python (3.6, I think). Use the `str.format()` method for older versions. – Keith Mar 25 '20 at 01:04
  • @samuel Another thing, you might need to update the print as follwos: ```print("Today's price: {}, yesterday's price: {}".format(today_price, yesterday_price))``` – dvlper Mar 25 '20 at 01:17

0 Answers0