Question

I'm having trouble with the following Python homework assignment question in ZyBooks: 2.14 HW: Driving costs...

I'm having trouble with the following Python homework assignment question in ZyBooks:

2.14 HW: Driving costs

Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.

Ex: If the input is:

20.0
3.1599

Then the output is:

1.579950 7.899750 63.198000

Any assistance is greatly appreciated. Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

miles = float(input()) # miles per gallon
dollars = float(input()) # dollars per gallon

ms = [10, 50, 400] # taking into a list
result = [] # will have results

for m in ms:
result.append((dollars/miles)*m)

print(("%.6f %.6f %.6f") % (result[0], result[1], result[2]))

#Please up vote or comment if you have any doubts. Happy Learning!

Add a comment
Know the answer?
Add Answer to:
I'm having trouble with the following Python homework assignment question in ZyBooks: 2.14 HW: Driving costs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3 please. 6.27 (Functions) HW: Driving cost - functions Write a function DrivingCost with input...

    Python 3 please. 6.27 (Functions) HW: Driving cost - functions Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. Ex: If the function is called with 50 20.0 3.1599, the function returns 7.89975. Define that function in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both floats). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your DrivingCost function three...

  • PLEASE WRITE IN C++ 2.25 LAB: Driving costs Driving is expensive. Write a program with a...

    PLEASE WRITE IN C++ 2.25 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements. Ex: If the input is: 20.0 3.1599 the output is: 1.58 7.90 63.20 Note:...

  • Driving cost - methods

    3.14 LAB: Driving cost - methodsWrite a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975.Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times.Output each...

  • LOGIC TUI Computer Program CHALLENGE ACTIVITY 2.9.2: Code basics See Coral: Code basics for solution help....

    LOGIC TUI Computer Program CHALLENGE ACTIVITY 2.9.2: Code basics See Coral: Code basics for solution help. Jump to level 1 Write code that outputs: A3 G7 TOUS: Home 3.6. Variables/Assignments: Driving costs My library > PRG 211: Algorithms & Logic for Computer Programming home > 6: Variables/Assignments: Driving costs zyBooks catalog He Start Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles,...

  • I'm having trouble figuring out the C++ code for the following assignment, keep getting errors. Help?...

    I'm having trouble figuring out the C++ code for the following assignment, keep getting errors. Help? Write a program that calculates a discount for buying certain quantities of coffee. Consider the following scenario: A coffee company sells a pound of coffee for $12.99. Quantity discounts are given according to the table below. Quantity Discount 5-9 5% 10-19 10% 20-29 15% 30 or more 20% Write a program that asks for the number of pounds purchased and computes the total cost...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT