Exercise II

අද අපි දැනට ඉගෙනගෙන තියන දේවල්වලින් පොඩි Exercise එකක් කරමු. දැනට අවුරුදු 10-15 කලින් බැංකුවකට එහෙම ගියානම් ඔයාලා දැකලා  ඇති ලොකු monitor වල කොළ පාටට Command Line Interface වලින් වැඩකරන programs. ඒ වගේ සරල program එකක් තමයි අපි අද code කරන්න යන්නේ.

අපේ program එකේදී වෙන්නේ බැංකුවට යම් මුදල් ප්‍රමාණයක් යම් අවුරුදු ගාණකට තැම්පත් කරාම අදාළ වර්ෂයට එකතුවන පොලිය සහ වර්ෂ අවසානයේ ශේෂය පෙන්වීම. මේ සදහා අපි බාවිතා කරන්නේ සරල for loop එකක්. Code එක පහත තියනවා.

මුලින්ම අපි heading එකක් දාමු

print("Interest Calculator")

පොඩි Space එකක් තියාගමු 

print("")

දැන් inputs ටික දෙන්න ඕනේ 

years=int(input("Number of Years:"))
r=float(input("Interest Rate(%):"))
dep=float(input("Deposit:"))
r = r/100

print("")

අපේ output ටික ලස්සනට columns වලට එනවනම් ලස්සන නිසා මේ වගේ table heads ටිකක් print කරගමු.

x =("year"+"     "+"Starting Balnce"+"       "+"Interest"+"      "+"Ending Balance")

print (x)

ඔන්න ඊලගට අපේ equation එකත් එක්ක for loop එක 

for i in range (1,years+1):
     
     interest=dep*r
     end = dep + interest
    
     
     print (i,"      ",(int(dep)),"                ",(int(interest)),"           ",(int(end)))

     dep=end

මෙහෙම code එක ඉවර කරමු 

print("")

input("Press Enter to Exit")     

    
සම්පුර්ණ code එක එන්නේ මෙහෙමයි

print("Interest Calculator")

print("")

years=int(input("Number of Years:"))
r=float(input("Interest Rate(%):"))
dep=float(input("Deposit:"))
r = r/100
print("")

x =("year"+"     "+"Starting Balnce"+"       "+"Interest"+"      "+"Ending Balance")
print (x)

for i in range (1,years+1):
     
     interest=dep*r
     end = dep + interest
    
     
     print (i,"      ",(int(dep)),"                ",(int(interest)),"           ",(int(end)))
     dep=end


print("")

input("Press Enter to Exit")     
    

අපේ program එක run වෙන්නේ මෙහෙමයි