In: Computer Science
Collect Customer Data - Part 2
Prompt: "Starting Odometer Reading:\n"
Variable: odoStart = ?
Prompt: "Ending Odometer Reading:\n"
Variable: odoEnd = ?
Add code to PRINT odoStart and odoEnd variables as well as the totalMiles to check your work.
The following data will be used as input in the test:
import sys
'''
Section 1: Collect customer input
'''
#Add customer input 1 here, rentalCode = ?
#Collect Customer Data - Part 2
#4)Collect Mileage information:
#a) Prompt the user to input the starting odometer
reading and store it as the variable odoStart
#Prompt -->"Starting Odometer Reading:\n"
# odoStart = ?
#b) Prompt the user to input the ending odometer reading and store it as the variable odoEnd
#Prompt -->"Ending Odometer Reading:"
# odoEnd = ?
#c) Calculate total miles
#Print odoStart, odoEnd and totalMiles
# Calculate Charges 2
## Calculate the mileage charge and store it
as
# the variable mileCharge:
#a) Code 'B' (budget) mileage charge: $0.25 for each mile driven
#b) Code 'D' (daily) mileage charge: no charge if
the average
# number of miles driven per day is 100 miles or less;
# i) Calculate the averageDayMiles
(totalMiles/rentalPeriod)
# ii) If averageDayMiles is above the 100 mile per
day
# limit:
# (1) calculate extraMiles (averageDayMiles -
100)
# (2) mileCharge is the charge for extraMiles,
# $0.25 for each mile
#c) Code 'W' (weekly) mileage charge: no charge if
the
# average number of miles driven per week is
# 900 miles or less;
# i) Calculate the averageWeekMiles (totalMiles/
rentalPeriod)
# ii) mileCharge is $100.00 per week if the average number of miles driven per week exceeds 900 miles
Im getting a Error on my Script at line 55:
LAST RUN on 9/14/2019, 8:44:31 AM
Check 1 failed
Output:
File "rental_car-customer-data-2.py", line 55 elif rentalCode == 'W' or rentalCode=='w': ^ SyntaxError: invalid syntax
Expected:
Starting Odometer Reading: Ending Odometer Reading: 1234 2222 988
My Script:
import sys
'''
Section 1: Collect customer input
'''
#Add customer input 1 here, rentalCode = ?
rentalCode = input("(B)udget, (D)aily, or (W)eekly
rental?\n")
print (rentalCode)
#Collect Customer Data - Part 2
#4)Collect Mileage information:
#a) Prompt the user to input the starting odometer
reading and store it as the variable odoStart
#Prompt -->"Starting Odometer Reading:\n"
# odoStart = ?
odoStart = input('Starting Odometer Reading: ')
#b) Prompt the user to input the ending odometer
reading and store it as the variable odoEnd
#Prompt -->"Ending Odometer Reading:"
# odoEnd = ?
odoEnd = input('Ending Odometer Reading: ')
#c) Calculate total miles
totalMiles = int(odoEnd) - int(odoStart)
#Print odoStart, odoEnd and totalMiles
print (odoStart)
print (odoEnd)
print (totalMiles)
# Calculate Charges 2
## Calculate the mileage charge and store it
as
# the variable mileCharge:
#a) Code 'B' (budget) mileage charge: $0.25 for each
mile driven
if rentalCode == "B" or rentalCode=='b':
mileCharge = totalMiles * 0.25
#b) Code 'D' (daily) mileage charge: no charge if the
average
# number of miles driven per day is 100 miles or less;
# i) Calculate the averageDayMiles
(totalMiles/rentalPeriod)
elif rentalCode == "D" or rentalCode=='d':
rentalPeriod = int(input('Enter days rented: '))
averageDayMiles = totalMiles/rentalPeriod
if averageDayMiles <= 100:
mileCharge=0
# ii) If averageDayMiles is above the 100 mile per
day
# limit:
# (1) calculate extraMiles (averageDayMiles -
100)
else:
# (2) mileCharge is the charge for extraMiles,
# $0.25 for each mile
mileCharge = (averageDayMiles-100) *0.25
#c) Code 'W' (weekly) mileage charge: no charge if
the
# average number of miles driven per week is
# 900 miles or less;
elif rentalCode == 'W' or rentalCode=='w':
rentalWeek = int(input('Enter rental week: '))
averageWeekMiles = totalMiles / rentalWeek
if averageWeekMiles<=900:
mileCharge=0
else:
mileCharge=100*rentalWeek
print('Charges : ${}'.format(mileCharge))
# i) Calculate the averageWeekMiles (totalMiles/
rentalPeriod)
# ii) mileCharge is $100.00 per week if the average number of miles driven per week exceeds 900 miles
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! =========================================================================== def compute_bill(code,days,start_reading,end_reading): distance=getDistance(start_reading,end_reading) if code=='B': return 40*days + (distance)*0.25 elif code=='D': average= (distance)/days if average<=100: return 60*days else: print(distance) return 60*days+ 0.25*(distance-days*100) elif code=='W': average_weekly=(distance)*7/days if average_weekly<=900: return 190*(days)/7 elif average_weekly<=1500: return 100*(days)/7 else: return 200*days/7 + (average_weekly-1500)*0.25 else: return 0 def getDistance(start_reading,end_reading): if start_reading > end_reading: distance = (1+(999999 - start_reading) + end_reading) / 10.0 else: distance = end_reading - start_reading distance /= 10.0 return distance def printInstructions(): print('Welcome to car rentals.') print('At the prompts, please enter the following:') print('Customer\'s classification code (a character: BDW)') print('Number of days the vehicle was rented (int)') print('Odometer reading at the start of the rental period (int)') print('Odometer reading at the end of the rental period (int)') def main(): #printInstructions() while True: answer=input('Would you like to continue (Y/N)? ') if answer=='Y': while True: code = input('Customer code (BDW): ').upper() if code not in ['B','D','W']: print('*** Invalid customer code. Try again. ***') else: break days=int(input("Number of days: ")) start_reading=int(input('Odometer reading at the start: ')) end_reading=int(input('Odometer reading at the end: ')) bill=compute_bill(code,days,start_reading,end_reading) print('Customer summary:') print('classification code: {}'.format(code)) print('rental period (days): {}'.format(days)) print('odometer reading at start: {}'.format(start_reading)) print('odometer reading at end: {}'.format(end_reading)) print('number of miles driven: {}'.format(getDistance(start_reading,end_reading))) print('amount due: $ {0:.2f}'.format(bill)) else: print('Thank you for your loyalty.') break main()
=====================================================================