# Syntax Error Line 7

``````print('How Much I Spend On Gas')
Miles = float( input('How many miles driven? '))
Gas = float( input('How many gallons were used? '))
MPG = Miles / Gas
print('Miles per gallon used:', '%.2f' % MPG)
fuel_cost = float( input('Cost of Fuel?: ')
print('Total Cost:',( MPG * fuel_cost))
``````

Getting a syntax error on line 7. Not sure why? Any help is appreciated.

Jon

Is this a homework question? I don’t recognize it as being from any exercises here.

Given you are using the `input()` function, and not `raw_input()` I’m assuming this is Python 3 code.

The error is above that, in line 6. Missing closing paren.

Was expecting to see errors since your math is a little off…

``````How Much I Spend On Gas
How many miles driven? 100
How many gallons were used? 4
Miles per gallon used: 25.00
Cost of Fuel?: 12
Total Cost: 300.0
>>>
``````

It is an example I was using for a forum post. I have been trying out code and creating examples for practice and to become more proficient. You are correct it was from Python 3. Thank you for your assistance it works now, I was thrown off by the error being expressed in line 7, I’ll keep this in mind for the future. I’ll have to check my math I thought it was straight forward but I have been more concerned about the code.

Here is a revised version with correction…

``````print ('Fuel Cost')
miles = float(input('How many miles driven? '))
fuel = float(input('How many gallons were used? '))
print ('Miles per gallon used: %.2f' % (miles / fuel))
fuel_cost = float(input('Cost of Fuel?: '))
print ('Total Cost: %.2f' % (fuel * fuel_cost))
``````

Excellent thank you!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.