Skip to content
Advertisement

Second instance of a money value print returns a value different than the first print with Python

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:

JavaScript

it prints as:

JavaScript

The second part of the code, for the receipt is:

JavaScript

it prints as:

JavaScript

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.

JavaScript

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.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement