Ex4.py Syntax Error

So I keep trying to find the syntax error here in ex4, but I still cannot pinpoint exactly what it is because I typed out everything that Zed said. Can someone look at it and tell me what needs to be fixed based off of what you see?

Hello @evancruz1

When mixing a string and variables in a print function you can do this:

print( "we need to put about %d in each car"  % (average_passenger_per_car,)


print( "we need to put about {} in each car" .format(average_passenger_per_car)

or the newest way that requires pythot3.6 or higher

print(f" we need to put about {average_passenger_per_car}  in_each_car")

It is always easier if we can see all of the code if you need help.
Copy and paste your code like this:

#here you paste in your code.
def my_first_function():
    print("Eureka! it works")
1 Like

Hello @evancruz1,

Or another method is how Zed wrote in the book in ex4. You misplaced the first comma, which should be out of the first quotes:

print("We need to put about", average_passengers_per_car, "in each car.")

Hello @puskini (eagle eye :slight_smile: )

I missed that one.

And I did not think about that way of printing out also works.
So now I know about four ways to print.

I wonder which is best to use? Perhaps one can choose a favourite and stick to it as long as it works with the version of Python?

Hi @ulfen69,

Thank you also for the 3 other ways! I have already written them down (it is nice to have them all in one place).

Yes, I think it is a matter of preference, of the version of Python that you use, and of the trend in the Python community.

Got it puskini; thank you.

1 Like