Python 草拟租车账单脚本数学问题
我的任务是为我的python初学者课程创建一个租车计费脚本。然而,当我运行我的程序时,“最终总数”是远远不够的,有人看到我没有注意到的错误吗 这是我的消息来源Python 草拟租车账单脚本数学问题,python,Python,我的任务是为我的python初学者课程创建一个租车计费脚本。然而,当我运行我的程序时,“最终总数”是远远不够的,有人看到我没有注意到的错误吗 这是我的消息来源 import sys ''' Section 1: Collect customer input ''' ##Collect Customer Data - Part 1 ##1) Request Rental code: #Prompt --> "(B)udget, (D)aily, or (W)eekly rental?
import sys
'''
Section 1: Collect customer input
'''
##Collect Customer Data - Part 1
##1) Request Rental code:
#Prompt --> "(B)udget, (D)aily, or (W)eekly rental?"
#rentalCode = ?
#Ask a question
#Get an answer
rentalCode = input("(B)udget, (D)aily, or (W)eekly rental?\n")
#2) Request time period the car was rented.
daysRented = 0
weeksRented = 0
if rentalCode == 'B' or rentalCode == 'D':
rentalPeriod = input("Number of Days Rented:\n")
else:
rentalPeriod = input("Number of Weeks Rented:\n")
budget_charge = (40.00)
daily_charge = (60.00)
weekly_charge = (190.00)
if rentalCode == "B":
baseCharge = int(rentalPeriod) * int(budget_charge)
elif rentalCode == "D":
baseCharge = int(rentalPeriod) * int(daily_charge)
elif rentalCode == "W":
baseCharge = int(rentalPeriod) * int(weekly_charge)
#this block prompts the user to input the starting and ending mileage and assigns them to the variable odoStart and odoEnd.
odoStart = input("Starting Odometer Reading:\n")
odoEnd = input("Ending Odometer Reading:\n")
#this block of code calculates the number of miles driven while the vehicle was rented
#and assigns the number to the variable totalMiles.
totalMiles = int(odoEnd) - int(odoStart)
if rentalCode == "B":
mileCharge = float(totalMiles) * 0.25;
#this block of code states if the user inputs D as the rental code, then the average
#day miles is calculated. if the average day miles is less than or equal to 100, then the #mile charge is 0. if it is more,
#than 100 is subtracted from it, and the calculation of
#.25 cents per mile times the number of days is calculated an assigned to the variable.
#mileCharge.
elif rentalCode == "D":
averageDayMiles = float(totalMiles)/float(rentalPeriod);
if float(averageDayMiles) <= 100:
extraMiles = 0;
else:
extraMiles = float(averageDayMiles) - 100;
mileCharge = (.25 * float(extraMiles)) * float(rentalPeriod);
#this block of code states that if the user inputed W for the rental code, then the
#average weekly miles is calculated. if the average weekly miles is less than or equal
#to 900, the mile chwrge is 0.if it is more, the calculation of 100 times the number of #weeks rented is computed and assigned
# to the variable mile charge.
elif rentalCode == "W":
averageWeekMiles = float(totalMiles)/ float(rentalPeriod);
if averageWeekMiles <= 900:
mileCharge = 0;
else:
mileCharge = 100 * float(rentalPeriod);
#this code calculates the base charge + the mile charge and assigns it to the variable
#amtdue for the cost.
amtDue = float(baseCharge) + float(mileCharge)
print("Rental Summary")
print("Rental Code: " + str(rentalCode))
print("Rental Period: " + str(rentalPeriod))
print("Starting Odometer: " + str(odoStart))
print("Ending Odometer: " + str(odoEnd))
print("Miles Driven: " + str(totalMiles))
print("Amount Due: " + "$" + str(amtDue))
正如你所看到的,它输入了一组我必须匹配的变量,我唯一关心的不是最终的总数是324.40美元,它是420.00美元。我在数学中没有看到什么?任何有用的东西,我对Python都是新手。正确的结果不应该是$422.0,因为((988/5)-100)*0.25*5+60*5=422,其中60*5是基本价格,((988/5)-100)*0.25*5是额外的总里程费用吗?
Check 1 failed
(B)udget, (D)aily, or (W)eekly rental?
Number of Days Rented:
Starting Odometer Reading:
Ending Odometer Reading:
Rental Summary
Rental Code: D
Rental Period: 5
Starting Odometer: 1234
Ending Odometer: 2222
Miles Driven: 988
Amount Due: $324.40