Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- #deklarasifungsi
- def round_decimals_up(number:float, decimals:int=2):
- """
- Returns a value rounded up to a specific number of decimal places.
- """
- if not isinstance(decimals, int):
- raise TypeError("decimal places must be an integer")
- elif decimals < 0:
- raise ValueError("decimal places has to be 0 or more")
- elif decimals == 0:
- return math.ceil(number)
- factor = 10 ** decimals
- return math.ceil(number * factor) / factor
- #input
- pinjamanValue = int(input("Pinjam berapa: \n$ "))
- bulanValue = int(input("Ambil brp bulan: \n"))
- rateValue = float(input("Suku Bunga (%): \n"))
- #menentukan nilai awal pinjaman, durasi pinjaman, dan suku bunga (setiap thn)
- P = pinjamanValue
- months = bulanValue
- rate = rateValue/100
- #hitung biaya yg hrs dibayar tiap bulan
- hasil = (rate/12) * (1/(1-(1+rate/12)**(-months)))*P
- hasilbulat = round_decimals_up(hasil)
- #hitung total bayar
- totalbyr = round_decimals_up(hasil)*bulanValue
- #hitung bunga
- bungaValue = totalbyr-pinjamanValue
- bungaValueBulat = round(bungaValue,2)
- #cetak hasil
- print("")
- print("Hasil")
- print("===================")
- print("Detail pinjaman:")
- print("$",pinjamanValue,"|",bulanValue,"Bln")
- print("")
- print ("Cicilan tiap bln:")
- print ("$",hasilbulat)
- print("Total yg hrs dbyr:")
- print("$",totalbyr)
- print("Bunga:")
- print("$",bungaValueBulat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement