A car rental company has three types of cars for customers to choose. SUV: $55 per day for first 7 days. $47 per day starting from the 8th day. Minivan: $49 per day for first 7 days. $42 per day starting from the 8th day. Hybrid: $44 per day for first 7 days. $38 per day starting from the 8th day. Write a Python program to do the following. (a) [4 points] Ask user to choose car type. Enter S for SUV, M for minivan or H for hybrid. User may enter uppercase or lowercase letter. Both S and s should be accepted for SUV. Both M and m should be accepted for minivan. Both H and h should be accepted for hybrid. If an invalid car type is entered, display "Invalid car type" and ask the user to reenter repeatedly until a valid car type is entered. (b) [4 points] Ask user to enter number of days. Since user is expected to enter a whole number, it is safe to convert it to an integer. A minimum of 2 days rental is required. If number of days is smaller than 2, display "Must be at least 2 days" and ask user to reenter repeatedly until 2 or larger is entered. (c) [8 points] Calculate and display rental fee. The following is an example: Enter S for SUV, M for minivan, H for hybrid: x Invalid car type. Enter S for SUV, M for minivan, H for hybrid: F Invalid car type. Enter S for SUV, M for minivan, H for hybrid: m Enter number of days: 1 Must be at least 2 days. Enter number of days: 0 Must be at least 2 days. Enter number of days: 8 Rental fee: 385

Respuesta :

Answer:

type=""

while(True):

 type=input("Enter S for SUV, M for minivan, H for hybrid: ").lower()

 if type=="s" or type=="m" or type=="h":

   break

 print("Invalid car type.")

days=0

amount=0

while(True):

 days=int(input("Enter number of days: "))

 if(days>=2):

   break

 print("Must be at least 2 days.")

if(type=="s"):

 if(days<=7):

   amount=days * 55

 else:

   amount = 7 * 55

   amount = amount+(days-7) * 47

if(type=="m"):

 if(days<=7):

   amount=days * 49

 else:

   amount = 7 * 49

   amount = amount+(days-7) * 42

if(type=="h"):

 if(days<=7):

   amount=days * 44

 else:

   amount = 7 * 44

   amount = amount+(days-7) * 38

print("Rental fee: ",amount)

Explanation: