Homework 1
CS2110 Programming for Informatics
Due Thursday, Feb. 4, 2021, by 10:00pm
6 points
Note: I strongly suggest completing DS Assignment 1 (will be published Thursday morning, Jan. 28) before starting HW1. The small problems in DS1 will be helpful in HW1. Hints and an outline for completing HW1 will also be given in lecture.
1. Write a Python function, tripCostData(distanceKM, vehSpeedMPS, vehKPL, gasCostPerLiter, hotelCostPerNight, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay) that takes as input:
- distanceKM: the trip's distance in kilometers (type: float)
- vehSpeedMPS: the vehicle's speed during the trip, in meters per second (type: float)
- vehKPL: the vehicle fuel efficiency in kilometers per liter (type: float)
- gasCostPerLiter: the price of one liter of gas in dollars (type: float)
- hotelCostPerNight: cost of one night in a hotel in dollars (type: float)
- breakfastCostPerDay: cost of a day's breakfast in dollars (type: float)
- lunchCostPerDay: cost of a day's lunch in dollars (type: float)
- dinnerCostPerDay: cost of a day's dinner in dollars (type: float)
and returns five values (in this order):
- the total cost of the trip in dollars (type: float)
- the gas cost of the trip in dollars (type: float)
- the total food cost of the trip in dollars (type: float)
- the numbers of lunches required (type: int)
- the number of hotel nights required (type: int)
Presume that you can only drive 8 hours per day. So, if a trip requires 15.25 hours, it will require
a one-night hotel stay at an additional cost (beyond gas and food costs) equal to hotelCostPerNight.
Important notes on cost:
- No hotel is needed on the day a trip ends. If a trip requires 8.0 hours, it does not require a hotel stay. Similarly, a trip of 16.0 hours requires one night of hotel, not two.
- No breakfast is needed on the first day of a trip.
- No dinner is needed on the final day of a trip.
- Lunch is needed only on days with more than 4.0 hours of travel.
2. Write a Python function, compareVehiclesForTrip(distanceM, veh1Name, veh1SpeedMPH, veh1MPG, veh2Name, veh2SpeedMPH, veh2MPG, gasCostPerGallon, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay, hotelCostPerNight) that computes the cost and other information of a trip for two different vehicles, and then prints information about the cost along a recommendation of vehicle should be used to save money. (Note: if trip cost is the same for both vehicles, say something appropriate).
The function's parameters are:
- distanceM: the trip's distance in miles (type: float)
- veh1Name: a string representing the first vehicle (e.g. "Tesla")
- veh1SpeedMPH: vehicle 1's speed in miles per hour (type: float)
- veh1MPG: vehicle 1's fuel efficiency in miles per gallon (type: float)
- veh2Name: a string representing the second vehicle (e.g. "BYD")
- veh2SpeedMPH: vehicle 2's speed in miles per hour (type: float)
- veh2MPG: vehicle 2's fuel efficiency in miles per gallon (type: float)
- gasCostPerGallon: the price of one gallon of gas in dollars (type: float)
- breakfastCostPerDay: cost of a day's breakfast in dollars (type: float)
- lunchCostPerDay: cost of a day's lunch in dollars (type: float)
- dinnerCostPerDay: cost of a day's dinner in dollars (type: float)
- hotelCostPerNight: cost of one night in a hotel in dollars (type: float)
compareVehiclesForTrip must make two calls to Q1's tripCostData function.
Note: before calling tripCostData you should convert units using good accurate conversion factors for miles/kilometers and gallons/liters.
For example,
>>> compareVehiclesForTrip(1000.0, "Bugatti", 100.0, 1.0, "Vespa", 27.0, 100.0, 2.10, 11.0, 23.0, 55.0, 6.50)
1000.0 miles in vehicle 'Bugatti' will cost $2195.50, including:
$6.50 for 1 hotel nights, $2100.00 for gas, and $89.00 for food (including 1 lunch)
1000.0 miles in vehicle 'Vespa' will cost $426.00, including:
$26.00 for 4 hotel nights, $21.00 for gas, and $379.00 for food (including 5 lunches)
To save money, use 'Vespa'
>>>
3. Write function testQ1() that makes at least five calls to tripCostData(...) with different arguments.
4. Write function testQ2() that makes at least five calls to compareVehiclesForTrip(...) with different arguments.
Submit to ICON one python file containing all four function definitions. The file must not include any code (except "import math") that is not part of a function definition.
Make sure your functions are named exactly (including upper/lower case usage) as in the specification, with the same set of parameters, in the same order .