0
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
    dm = miles_per_gallon / dollars_per_gallon
    gc = driven_miles / dm
    return gc
    
gas_efficiency = float(input())
gas_cost = float(input())
    
print("{:.2f}".format(driving_cost(20, gas_efficiency, gas_cost)))
print("{:.2f}".format(driving_cost(75, gas_efficiency, gas_cost)))
print("{:.2f}".format(driving_cost(500, gas_efficiency, gas_cost)))

Where would I place end = ' ' to get them to print on the same line?

Br3xin
  • 116
  • 6
  • 1
    So, you know about the `end=` parameter. What have you tried? – quamrana Sep 17 '22 at 20:59
  • I'm really struggling on where to place the parameter... – Br3xin Sep 17 '22 at 21:00
  • 1
    I think this should work. print("{:.2f}".format(driving_cost(20, gas_efficiency, gas_cost)),end=" ") – YJR Sep 17 '22 at 21:00
  • 1
    So, you've tried to use it. Please update your question with your attempts. – quamrana Sep 17 '22 at 21:01
  • If you've tried to use `end=`, but got it wrong, please show it because there are likely to be future programmers who make the same mistake and might be able to find this question. – quamrana Sep 17 '22 at 21:05

1 Answers1

1

If you really want them all on the same line, a more effective approach might be to have a single format string and pass three values to format.

print("{:.2f} {:.2f} {:.2f}".format(
  driving_cost(20, gas_efficiency, gas_cost), 
  driving_cost(75, gas_efficiency, gas_cost), 
  driving_cost(500, gas_efficiency, gas_cost)
))
Chris
  • 26,361
  • 5
  • 21
  • 42