Record#
- Today I learned a new way of looping, the for loop. This type of loop is suitable for situations where the number of iterations is known in advance.
- The for loop can be used without declaring variables, you can write them directly in the loop.
- Programmers commonly use i, j, and k as loop variables, using words with meaningful expressions might be better.
- Today's code writing program is an interest calculator, overall there are no major issues, but I still don't quite understand calculations like +=.
CODE#
print("Repayment Calculator")
print()
n1 = int(input("Enter your loan amount: "))
n2 = int(input("Enter your interest rate: "))
n3 = int(input("Enter your loan term in years: "))
total = n1
print()
print("Your loan amount is: ", n1, ", Your loan term is: ", n3, ", Your interest rate is: ", n2, "%")
print()
for years in range(n3):
n1 += n1 * n2 / 100
print("In year", years + 1, ", your repayment amount is: ", round(n1, 2), "Interest amount is: ",
round((n1 - total), 2))