## Instructions

**Objective**

## Requirements and Specifications

**Important note:**To write a python 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.

- Remember! Your submission MUST include the hawkID function (modified with your own hawkID). See the course website and this template file
. Don't import the template file. Just directly add the code for the hawkID() function into your hw1 Python file.**hawkIDtemplate.py** - 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)
- 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)
- 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.
- 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)
- 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).

**and returns seven values (in this order):
**

**Important rules for cost computation:
**

**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)

>>>

**Requirements:
**

**Source Code
**

#

# Every homework and discussion assigmnent MUST contain this hawkID function,

# modified to return your own Hawk ID

#

# Note that your HawkID is all (or mostly) letters. It is not your ID number.

#

# Replace 'yourhawkid' with your Hawk ID (e.g. change "yourhawkid" to "cremer")

#

def hawkID():

return("yourhawkid")

def computeTripData(distanceK, vehSpeedMPS, vehKPL, gasCostPerLiter, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay, hotelCostPerDay):

# First, calculate the length of the trip in hours

trip_length = distanceK*1000.0 / vehSpeedMPS # This is in seconds. Convert to hours

trip_length = trip_length / 3600.0 # in hours

# Compute the amount of liters of gas to be used

gas_liters = distanceK / vehKPL # in liters

# Compute gas cost of the trip in dollars

gas_cost = gasCostPerLiter*gas_liters

# Compute number of nights

hours_required = trip_length # in hours

n_nights = 0

n_breakfast = 0

n_dinner = 0

n_lunch = 0

n_nights = int(hours_required/8)

n_breakfast = int(hours_required/8)

n_lunch = int(hours_required/8)

n_dinner = int(hours_required/8)

# Compute number of rest days

n_rest = 0

hours_required = trip_length

n_rest= int(hours_required / 40.0)

n_nights += n_rest

n_dinner += n_rest

n_breakfast += n_rest

# For every rest day there will be one breakfast, one lunch and one dinner

# Calculate number of breakfast

if trip_length > 4.0: # If the trip is more than 4 hours, a lunch is required

n_lunch += 1

#n_breakfast += 1

#n_dinner += 1

# We compute the total length of the trip in days

trip_length_days = trip_length / 24.0

# Compute cost of breakfast

breakfast_cost = breakfastCostPerDay * n_breakfast

# Cost of dinner

dinner_cost = dinnerCostPerDay * n_dinner

# Hotel cost

hotel_cost = hotelCostPerDay * n_nights

# Compute the lunch cost

lunch_cost = lunchCostPerDay * n_lunch

# Compute the total cost

total_cost = gas_cost + breakfast_cost + dinner_cost + hotel_cost + lunch_cost

# Return results

return (trip_length, gas_cost, total_cost, n_breakfast, n_lunch, n_dinner, n_nights)

def printTripSummary(vehName, distanceM, vehSpeedMPH, vehMPG, gasCostPerGallon, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay, hotelCostPerNight):

# Calculate data

# Convert distance from miles to km

distanceK = distanceM *1.60934

# Convert speed from mph to m/s

vehSpeedMPS = vehSpeedMPH *0.44704

# Convert fuel's efficiency from miles per gallon to km per liter

vehKPL = vehMPG * 1.60934 / 3.78541

# Convert gas cost per gallon to cost per liter

gasCostPerLiter = gasCostPerGallon / 3.78541

# Convert hotel cost per nght to hotel Cost per day

hotelCostPerDay = hotelCostPerNight

(trip_length, gas_cost, total_cost, n_breakfast, n_lunch, n_dinner, n_nights) = computeTripData(distanceK, vehSpeedMPS, vehKPL, gasCostPerLiter, breakfastCostPerDay, lunchCostPerDay, dinnerCostPerDay, hotelCostPerDay)

print("{} trip of {:.1f} miles. Hotel nights: {}, Total cost: ${:.2f}".format(vehName, distanceM, n_nights, total_cost))

if __name__ == '__main__':

print(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)

print(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)

print(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)

print(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)

result = printTripSummary("Bugatti", 1400.0, 100.0, 20.0, 5.0, 8.0, 12.5, 24.0, 150.0)

printTripSummary('V3', 1231.5, 1.0, 10.0, 10.0, 6.0, 10.0, 23.0, 50.0)