Homework 1
CS1210, Fall 2021
Due Friday, Sep. 3, 2021, by 2:00pm
6 points
Important note: In this assignment no loops, lists, or dictionaries are allowed! Use simple variables, assignments, math expressions, functions, and if/else statements only!
Note: I strongly suggest completing DS Assignment 1 before starting HW1. It will be published Thursday, Aug. 26 and due Tuesday, Aug. 31. The small problems in DS1 will be helpful in HW1. Hints and an outline for completing HW1 will also be given in lecture.
0. Remember! Your submission MUST include the hawkID function (modified with your own hawkID). See the course website and this template file hawkIDtemplate.py. Don't import the template file. Just directly add the code for the hawkID() function into your hw1 Python file.
1. Implement function, computeTripData(distanceK, vehSpeedMPS, vehKPL, gasCostPerLiter, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay, hotelCostPerNight) that takes as input:
- distanceK: 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)
- 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)
and returns seven values (in this order):
- the length of the trip in hours (type: float)
- the gas cost of the trip in dollars (type: float)
- the total cost of the trip in dollars (type: float)
- the number of breakfasts required (type: int)
- the number of lunches required (type: int)
- the number of dinners required (type: int)
- the number of hotel nights required (type: int)
Important rules for cost computation:
- You can only drive 8 hours per day. Thus, if a trip requires 15.25 hours of driving, a one night hotel stay will be needed, costing an additional amount (beyond gas and food costs) equal to hotelCostPerNight. 17 hours of driving would require 2 hotel nights
- For every 40 hours of driving, a rest day is needed, adding one breakfast, lunch, and dinner, as well as two hotel nights to the total cost. Thus, a 39 hour trip requires 4 hotel nights, a 41 hour trip requires 6, a 79.9 hour trip requires 10, and an 80.5 hour trip requires 12.
- No hotel or meals are needed after a trip ends. If a trip requires 8.0 hours, it does not require a hotel stay nor dinner. Similarly, a 40-hour trip requires 4 hotel nights, not 5, and does not require a rest day and the associated costs.
- No breakfast is needed on the first day of a trip.
- Lunch is needed only on days with more than 4.0 hours of travel.
For example,
>>> computeTripData(1.0, 1000.0/3600, 2.0, 3.0, 5.0, 12.0, 21.0, 111.0)
(1.0, 1.5, 1.5, 0, 0, 0, 0)
>>> computeTripData(31.0, 2000.0/3600, 2.0, 3.0, 5.0, 12.0, 21.0, 111.0)
(15.5, 46.5, 207.5, 1, 2, 1, 1)
>>> computeTripData(80.5, 2000.0/3600, 2.0, 3.0, 5.0, 12.0, 21.0, 111.0)
(40.25, 120.75, 1014.75, 6, 6, 6, 6)
>>> computeTripData(200.0, 3.0, 2.0, 3.0, 5.0, 12.0, 21.0, 111.0)
(18.51851851851852, 300.0, 598.0, 2, 2, 2, 2)
>>>
2. Implement function, printTripSummary(vehName, distanceM, vehSpeedMPH, vehMPG, gasCostPerGallon, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay, hotelCostPerNight) that takes as input:
- vehName: a string representing the vehicle's name (e.g. "Fiat 500")
- distanceM: the trip's distance in miles (type: float)
- vehSpeedMPH: the vehicle's speed in miles per hour (type: float)
- vehMPG: the vehicle'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)
Requirements:
- printTripSummary must first convert from the US/non-metric input units (miles and gallons) to metric units (kilometers, meters, liters) suitable for passing to Q1's computeTripData function. Important: use good units-conversion constants, not rough/simple approximations like 1.6 km per mile. Good ones are easy to find. I will provide good ones in the slides of one of the upcoming lectures (but you'll have to find them :))
- printTripSummary must then make a call to Q1's computeTripData function to get the trip data.
- Finally, printTripSummary should construct a string summarizing the trip information, and both print and return that string. The format for the string is shown in the example below. Use the same punctuation and spacing as in the example. Dollar amounts must display two digits after the decimal place (even when it is .00).
For example,
>>> result = printTripSummary("Bugatti", 1400.0, 100.0, 20.0, 5.0, 8.0, 12.5, 24.0, 150.0)
Bugatti trip of 1400.0 miles. Hotel nights: 1, Total cost: $557.00
>>> result = printTripSummary('V1', 100.0, 10.0, 1.0, 5.0, 6.0, 10.0, 23.0, 1000.0)
V1 trip of 100.0 miles. Hotel nights: 1, Total cost: $1539.00
>>> result = printTripSummary('V2', 1231.5, 33.0, 111.0, 10.0, 6.0, 10.0, 23.0, 50.0)
V2 trip of 1231.5 miles. Hotel nights: 4, Total cost: $476.95
>>> printTripSummary('V3', 1231.5, 1.0, 10.0, 10.0, 6.0, 10.0, 23.0, 50.0)
V3 trip of 1231.5 miles. Hotel nights: 183, Total cost: $17528.50
'V3 trip of 1231.5 miles. Hotel nights: 183, Total cost: $17528.50'
>>>
Submit to ICON one python file containing the required functions. 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 .