Daily Coding Challenge - Fill The Tank

Tell us what’s happening:

I’ve completed two out of the five objectives, and my issue is that I can’t seem to round the outputs to two decimal places if they end in two zeros.

Your code so far

def cost_to_fill(tank_size, fuel_level, price_per_gallon): 
    requiredFuel = tank_size - fuel_level
    gallon_needed = price_per_gallon * requiredFuel
    totalAmount = round(gallon_needed, 2)
    return "$" + str(totalAmount)


print(cost_to_fill(20, 0, 4.00))
print(cost_to_fill(15, 10, 3.50))
print(cost_to_fill(18, 9, 3.25))
print(cost_to_fill(12, 12, 4.99))
print(cost_to_fill(15, 9.5, 3.98))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0

Challenge Information:

Daily Coding Challenge - Fill The Tank
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-09-18

find a method that does that, or you need to build the string manually

I tried to debug and it seems like issue may be due to str(totalAmount). totalAmount is round(gallon_needed, 2) so when float converted to string its always limits to one decimal. You may fix it by solving f-string

1 Like

Thank you so much! It worked!