Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

โปรแกรม Python คำนวณดอกเบี้ยทบต้น (Compound Interest)

โจทย์: กำหนด เงินต้น (P), อัตราดอกเบี้ย (R), เวลา (T) หาดอกเบี้ยทบต้น

สูตร: Compound Interest = P × (1 + R/100)ᵀ

โค้ดตัวอย่าง

def compound_interest(principle, rate, time):
    CI = principle * (pow((1 + rate / 100), time))
    print("Compound interest:", CI)

compound_interest(10000, 7.78, 2)

ผลลัพธ์

Compound interest: 11616.528400000001

โปรแกรม Python คำนวณดอกเบี้ยทบต้น (Compound Interest)

สรุป

เรียนรู้สูตรและโปรแกรม Python คำนวณดอกเบี้ยทบต้น (Compound Interest) จาก เงินต้น อัตรา และเวลา