Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives: use an if...else statement with multiple conditions to evaluate inpu

ID: 3598083 • Letter: O

Question

Objectives: use an if...else statement with multiple conditions to evaluate input perform calculations based on conditions Task: Write a well-documented program that will be used by a rental car company to determine how much to charge its customers. You should prompt the user to enter the number of days the car was rented and how many miles it was driven. A passenger car is rented for $15.00 per day plus $.40 per mile. However, the rate per mile goes down to $.35 if the car was driven 200 miles or more. Sales tax is 6% and the program should output a subtotal, tax amount, and total. Follow these steps: Declare the necessary variables. Assume the input for days will be a whole number but the miles driven may not be. Use the appropriate data type for the dollar amounts as well. Use the logic above to determine the charges for a customer based on the number of days a car was rented and the number of miles it was driven. To ensure that it would only need to be updated in a single location, the amount charged per day for renting a car should only appear in one calculation. All dollar amounts should be shown with a $ and have 2 numbers to the right of the decimal point. Be sure to include a blank line between the inputs and the results. Do your best to make it neat. Use the tab character to align all inputs and outputs as shown below. Example 1: Enter the number of days the car was rented: 1 Enter the number of miles the car was driven: 150 Subtotal: $75.00 Tax Amount: $4.50 Total: $79.50 Example 2: Enter the number of days the car was rented: 2 Enter the number of miles the car was driven: 399.5 Subtotal: $169.82 Tax Amount: $10.19 Total: $180.01

Explanation / Answer

The solution is implemented in Python3


#this method formats the string in desired method
def formatted(num):
return "$" + '{0:.2f}'.format(num)

def main():
number_of_days = int(input("Enter number of days the car was rented: "))
miles_driven = float(input("Enter the number of miles driven: "))

per_day_rent = 15 #in dollars
general_per_mile_rent = 0.40 #in dollars
special_per_mile_rent = 0.35 #in dollars
sales_tax = 0.06 # 6 percent

#calculating subtotal
if miles_driven >= 200 :
  subtotal = miles_driven*special_per_mile_rent + number_of_days*per_day_rent
else:
  subtotal = miles_driven*general_per_mile_rent + number_of_days*per_day_rent

#calculating tax
tax_amount = subtotal*sales_tax

#calculating total
total = subtotal + tax_amount

print("Subtotal: " + formatted(subtotal))
print("Tax Amount: " + formatted(tax_amount))
print("Total: " + formatted(total))


if __name__ == '__main__':
main()