How do I fix this code to get the proper output

IndifferentFento

This is the code:

amount_borrowed = float(input("Amount borrowed: $"))
interest_rate = float(input("Interest rate: "))
loan_length = int(input("Length of loan (months): "))
i = interest_rate/100
monthly_payment1 = (i / 12) * amount_borrowed    #this is the first part of the payment formula

monthly_payment2 = monthly_payment1 / 1 - (1 + i / 12)**-loan_length          
#second part of monthly payment formula

print("The monthly payment is ${:.2f}" .format(monthly_payment2))

I should get this output:

Amount borrowed: $100.00

Interest rate: 10.0

Length of loan (months): 12

The monthly payment is $8.79.

I keep on getting this:

Amount borrowed: $100

Interest rate: 10

Length of loan (months): 12

The monthly payment is $-0.07

Hemerson Tacon

Don't make much sense divide by 1. I think that you did forget a pair of parentheses in the denominator of the division. So, the following line

monthly_payment2 = monthly_payment1 / 1 - (1 + i / 12)**-loan_length

should be

monthly_payment2 = monthly_payment1 / (1 - (1 + i / 12)**-loan_length)

I tested here and get the expect value of $8.79

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I fix the Dataset to return desired output (pytorch)

How do I get proper parameter names in cgo exported functions?

How do I fix the following code so I get a reversed linked list for the output?

How do I get the same print format to output within julia code that I get in the julia console?

Why is this code not working, How do i fix it?

Why can't i get the proper output by this code?

Why do I get None in the output of this code?

How do I get proper output when I reverse a string in C using pointers

TypeError in React, how do I fix it so that the output is rendered correctly?

How to get the proper output in the C Program?

How do I output a proper resolution/frequency in text mode?

How do I fix this output?

How do I set this HDMI output fix permanent?

Why did I get the wrong output and how can I fix this?

code not generating proper output as I expected

Why I am not getting proper output in this code?

How do i get an output from this code using excel

why do I get this error, how do can I fix it

How do I get my code to only print one output?

How to change my code for a proper output

How can I get the proper name in the output of the following SQL query?

How can I fix the output problem in my code?

Why do I get this error, and how do I fix it?

Output is 0 no matter what - how do I fix this?

I do nor know how to fix code to get a result

Why do I not get any output for this code?

How do I fix this code so it produces an output?

How do I fix the output from always displaying 0 in the console?

How do I fix my `Any` class code to output data correctly?