Advertisement
Umarkov45

tutorialngutang.py

Sep 24th, 2022
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | Source Code | 0 0
  1. import math
  2.  
  3. #deklarasifungsi
  4. def round_decimals_up(number:float, decimals:int=2):
  5.     """
  6.    Returns a value rounded up to a specific number of decimal places.
  7.    """
  8.     if not isinstance(decimals, int):
  9.         raise TypeError("decimal places must be an integer")
  10.     elif decimals < 0:
  11.         raise ValueError("decimal places has to be 0 or more")
  12.     elif decimals == 0:
  13.         return math.ceil(number)
  14.  
  15.     factor = 10 ** decimals
  16.     return math.ceil(number * factor) / factor
  17.  
  18. #input
  19. pinjamanValue = int(input("Pinjam berapa: \n$ "))
  20. bulanValue = int(input("Ambil brp bulan: \n"))
  21. rateValue = float(input("Suku Bunga (%): \n"))
  22.  
  23. #menentukan nilai awal pinjaman, durasi pinjaman, dan suku bunga (setiap thn)
  24. P = pinjamanValue
  25. months = bulanValue
  26. rate = rateValue/100
  27.  
  28.  
  29.  
  30. #hitung biaya yg hrs dibayar tiap bulan
  31. hasil = (rate/12) * (1/(1-(1+rate/12)**(-months)))*P
  32. hasilbulat = round_decimals_up(hasil)
  33.  
  34. #hitung total bayar
  35. totalbyr = round_decimals_up(hasil)*bulanValue
  36.  
  37. #hitung bunga
  38. bungaValue = totalbyr-pinjamanValue
  39. bungaValueBulat = round(bungaValue,2)
  40.  
  41. #cetak hasil
  42. print("")
  43. print("Hasil")
  44. print("===================")
  45. print("Detail pinjaman:")
  46. print("$",pinjamanValue,"|",bulanValue,"Bln")
  47. print("")
  48. print ("Cicilan tiap bln:")
  49. print ("$",hasilbulat)
  50. print("Total yg hrs dbyr:")
  51. print("$",totalbyr)
  52. print("Bunga:")
  53. print("$",bungaValueBulat)
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement