Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I can't figure out what the syntax error is.

+4 votes
asked Oct 3, 2022 by Parker Weaver (160 points)
v = input ('Enter whether you are a veteran or not (Yes or No): ')

if v = Yes   #(says this is the syntax error)

    print (Thank you for your service!)

1 Answer

+5 votes
answered Oct 3, 2022 by Peter Minarik (88,520 points)

Your code correctly:

v = input ('Enter whether you are a veteran or not (Yes or No): ')
if v == "Yes":   #(says this is the syntax error)
    print("Thank you for your service!")

Here are some highlights:

  • strings need to be surrounded by quotes: double (") or single (')
  • you need a colon (:) at the end of the if's condition
  • to compare equality you need to use two equal signs: ==
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.