Very Basic Beginner Question

I’m just starting out learning Python with the LinkedIn Learning Programming Foundations: Fundamentals course. I’m following the exercises and copy and paste them into Visual Studio Code like the instructor does. Except when the instructor does it the code works, and when I do it, receive a
SyntaxError: invalid syntax message. Here’s the code, any help would be much appreciated:

def wash_car(amount_paid):
if (amount_paid == 12):
print(“Wash with tri-color foam”)
print(“Rinse twice”)
print(“Dry with large blow dryer”)

if (amount_paid == 6):
    print("Wash with white foam")
    print("Rinse once")
    print("Air dry") 

wash_car(6)

Does the error message indicate the line on which the problem occurred?

Thanks for the quick reply. It mentions line 1, here’s the whole thing:

/usr/local/bin/python3 “/Users/lancevallis/Desktop/Ex_Files_Programming_Foundations_Fundamentals/def wash_car():.py”
File “”, line 1
/usr/local/bin/python3 “/Users/lancevallis/Desktop/Ex_Files_Programming_Foundations_Fundamentals/def wash_car():.py”
^
SyntaxError: invalid syntax

Your code, as posted, is not formatted properly. For example, the indentation and quote marks are not displayed correctly in the first five lines. This might relate to the manner in which it was posted, rather than to how it is formatted on your computer. It is important to make sure the entire program is formatted correctly when you post it.

On my machine, it runs properly after the indentation and quotes are corrected. Below is the code, formatted properly.

def wash_car(amount_paid):
  if (amount_paid == 12):
    print("Wash with tri-color foam")
    print("Rinse twice")
    print("Dry with large blow dryer")
  if (amount_paid == 6):
    print("Wash with white foam")
    print("Rinse once")
    print("Air dry") 
wash_car(6)

Please copy it exactly as is, try to run it, and let us know what happens. If you receive an error message, we’ll need to see it.

I copied and pasted the code you posted and am still getting an error message:

/usr/local/bin/python3 “/Users/lancevallis/Desktop/Ex_Files_Programming_Foundations_Fundamentals/def wash_car():.py”
File “”, line 1
/usr/local/bin/python3 “/Users/lancevallis/Desktop/Ex_Files_Programming_Foundations_Fundamentals/def wash_car():.py”
^
SyntaxError: invalid syntax

Have you successfully run any other Python code on your computer with Visual Studio Code? If not, let’s try a simple program to make sure everything is set up properly.

Please let us know if this runs on your system:

print("Hello world!")

If that does not run properly, you may need to check out this page:

Ha, same SyntaxError: invalid syntax message when trying to run print(“Hello world!”). Reading the link you sent now. I thought I had been able to get some of the earlier exercises to run using Visual Studio Code. I’ve jumped around to Pycharm and Terminal though. Thanks for the help!

1 Like