Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please write code in python Part 1 For this project, you must write the code for the following function: def unit_converter(units, total_cost, from_currency, to_currency): The

please write code in python

image text in transcribedimage text in transcribedimage text in transcribed

Part 1 For this project, you must write the code for the following function: def unit_converter(units, total_cost, from_currency, to_currency): The function unit_converter converts the total_cost in from_currency to to_currency. units: number of gallons (for $) or liters (for C$) total_cost: USD dollars or CAD dollars paid for units from_currency: either '$' or 'C$' .to_currency: either '$' or 'C$' Here's a typical use: # CAD/liter to USD/gallon USD_per_gallon = unit_converter (61, 124.00, 'c$', 'S') # USD/gallon to CAD/liter CAD_per_liter = unit_converter (16, 45.0, 's', 'C$') You should use the same constant values for (unit conversions and exchange rates): LITERS_PER_GALLON = 3.78541 GALLONS_PER_LITER = 0.264172 # exchange rates CAD_TO_USD = 0.76 USD_TO_CAD = 1.31 You must handle all combinations of '$' and 'C$' for from_currency and to_currency. A '$' to '$' conversion would mean the answer is given in $/gallon. You can assume that if the from_currency is '$' then the units are gallons otherwise they are liters (we'll fix this later). The best strategy is to write the code that seems the clearest to you (perhaps using lots of if statements) and that it passes the tests. Write it so that you understand it. Don't continue until you pass the tests. Take a look at your code for unit_converter. Did you do any of the following: Did you repeat the same code in several places? (avoid this) Did you have more than one return statement? (avoid this) . Can you read your code? Did you use variables that describe what they hold or did you use single letters to name your variables? (do this)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

Which state has the highest sum of transaction amount?

Answered: 1 week ago