Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner Coding Help
#1
Hi,

I'm brand new to Python and don't understand what I've done wrong here, could someone please enlighten me?
_______________________________________________________________________________________

Here's my code:

question_know = "How many sides does a square have?"
question = "How many sides does a circle have?"

if question == question_know:
    print("4")

else:
    print(f"I don't know, why not try asking {question_know}")
_______________________________________________________________________________________

Here's my error:

Error:
File "/Users/callumbennett/Dropbox/Mac/Documents/P Projects/HelloWorld/Playground.py", line 8 print(f"I don't know, why not try asking {question_know}") ^ SyntaxError: invalid syntax [Finished in 2.348s]
_______________________________________________________________________________________

Thanks for your time.
Yoriz write Oct-30-2021, 01:47 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
I don't see what is causing the syntax error with the code from looking at the picture.
Please post the actual code and the error in code tags as instructed above and not pictures of code.
Reply
#3
Thanks for the fast reply to my issue, I have updated my post. Hope this is clearer.
Reply
#4
Thank you I ran the code that you have now added above and I get no error, it outputs the following.
Output:
I don't know, why not try asking How many sides does a square have?
What version of python are you using, does it have f strings?
f strings where added in version 3.6 https://docs.python.org/3/whatsnew/3.6.h...g-literals
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tic-Tac game (Beginner's coding) Shahmadhur13 5 3,090 Aug-29-2020, 08:40 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020