Question: Please write code in python. Was getting error message that is included below. Currency and Unit Conversion PETRO CANADA 153.4 libre-service The Currency/Volume Converter In

Please write code in python. Was getting error message that is included below. Please write code in python. Was getting error message that is includedbelow. Currency and Unit Conversion PETRO CANADA 153.4 libre-service The Currency/Volume ConverterIn a previous lesson we created a function named unit_converter that convertedfrom USD/gallon to CAD/liter. The issue with unit_converter is that it had

Currency and Unit Conversion PETRO CANADA 153.4 libre-service The Currency/Volume Converter In a previous lesson we created a function named unit_converter that converted from USD/gallon to CAD/liter. The issue with unit_converter is that it had a built in assumption -- regarding the input currency. We will fix this by adding another parameter to be explicit about the conversion. Both the 'from' currency and the 'to' currency will be added. 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$) 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, '', '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). You must handle all combinations of '$' and 'C$' for from_currency and to_currency. A's' 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. def unit_converter_v1(units, total_cost, from_currency,to_currency): if from_currency=='$' and to_currency=='cs': x= (total_cost*1.31)/(3.78541*units) elif from_currency=='cs' and to_currency=='$': x= (total_cost*0.76)/(0.264172*units) elif from_currency=='$' and to_currency == '$': x= (total_cost/units) #elif from_currency=='cs' and to_currency=='cs': else: x= (total_cost/units) return x Score 55/100 functions 10/10 suitel 0/45 Test Failed: False is not true : fail $ to $ suite2 45/45

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!