I’m working on a program that is a simulation of an order form/receipt. First, the program prints an invoice, then later prints a receipt based on which payment schedule the user selects (1-4 years) My problem is that I can’t find a way to get the invoice and receipt to print the same monthly payment. This is the code used for the invoice:
for NumYears in range (0, 4): NumYears += 1 NumPayment = NumYears * 12 FinanceFee = 39.99 * NumYears TotPrice = TotSalesPrice + FinanceFee MonPay = TotPrice / 12
it prints as:
# Years # Payments Financing Fee Total Price Monthly Payment ---------------------------------------------------------------------- 1 12 $39.99 $9,914.99 $826.25 2 24 $79.98 $9,954.98 $829.58 3 36 $119.97 $9,994.97 $832.91 4 48 $159.96 $10,034.96 $836.25 ---------------------------------------------------------------------
The second part of the code, for the receipt is:
MonPay1 = TotPrice / 12 MonPay2 = (TotPrice / 12) * 2 MonPay3 = (TotPrice / 12) * 3 MonPay4 = (TotPrice / 12) * 4 while True: if PayMethod == "1": print("Terms: 1 Total Payments: 12") break elif PayMethod == "2": print("Terms: 2 Total Payments: 24") break elif PayMethod == "3": print("Terms: 3 Total Payments: 36") break elif PayMethod == "4": print("Terms: 4 Total Payments: 48") break while True: if PayMethod == "1": print(f"Monthly payment: {MonPay1Dsp:>10s}") break elif PayMethod == "2": print(f"Monthly payment: {MonPay2Dsp:>10s}") break elif PayMethod == "3": print(f"Monthly payment: {MonPay3Dsp:>10s}") break elif PayMethod == "4": print(f"Monthly payment: {MonPay4Dsp:>10s}") break else: break
it prints as:
Sale price: $5,000.00 Trade Allowance: $1,000.00 Price after Trade: $4,000.00 ---------- HST: $750.00 License Fee: $75.00 Transfer Fee: $5,050.00 ---------- Total Sales Cost: $10,034.96 ---------------------------------- Terms: 1 Total Payments: 12 Monthly payment: $836.25 First payment date: 31-Jan-2022
What can I do to fix the discrepancy?
EDIT: Adding in all the calculations. I’ve gone over them a few times and can’t find the error. Maybe I’ve just been looking at it too long… I don’t know.
HST_FEE = .15 TRANS_FEE_LOW = 0.01 TRANS_FEE_HIGH = 0.026 LISC_FEE_LOW = 75.00 LISC_FEE_HIGH = 165.00 PriceAfterTrade = SellPrice - AmtTradeIn Taxes = HST_FEE * SellPrice if SellPrice <= 5000.00: LiscFee = LISC_FEE_LOW else: LiscFee = LISC_FEE_HIGH if SellPrice >= 20000.00: TransFee = (TRANS_FEE_HIGH * SellPrice) + SellPrice else: TransFee = (TRANS_FEE_LOW * SellPrice) + SellPrice TotSalesPrice = PriceAfterTrade + Taxes + LiscFee + TransFee
Advertisement
Answer
The error in your code just hit me: your calculations for MonPay1, … all used TotPrice, with the value set at the end of the invoice loop, so the value for 4 years!
Here is the code I rewrote (based on my understanding of your different values). You’ll probably have to tweak some things to fit your needs.
# Data SellPrice = 5000 AmtTradeIn = 1000 HST_FEE = .15 TRANS_FEE_LOW = 0.01 TRANS_FEE_HIGH = 0.026 LISC_FEE_LOW = 75.00 LISC_FEE_HIGH = 165.00 PriceAfterTrade = SellPrice - AmtTradeIn Taxes = HST_FEE * SellPrice if SellPrice <= 5000.00: LiscFee = LISC_FEE_LOW else: LiscFee = LISC_FEE_HIGH if SellPrice >= 20000.00: TransFee = (TRANS_FEE_HIGH * SellPrice) + SellPrice else: TransFee = (TRANS_FEE_LOW * SellPrice) + SellPrice TotSalesPrice = PriceAfterTrade + Taxes + LiscFee + TransFee print(TotSalesPrice) # Code for invoice MonPay=[0] for NumYears in range (1, 5): NumPayment = NumYears * 12 FinanceFee = 39.99 * NumYears TotPrice = TotSalesPrice + FinanceFee MonPay.append(TotPrice / 12 / NumYears) print(MonPay[NumYears]) # Code for receipt PayMethod = "1" #This is an example for testing purpose print("Terms: " + PayMethod + " Total Payments: "+str(12*int(PayMethod))) print(f"Monthly payment: ${MonPay[int(PayMethod)]}")