Code 111
Code 111
interest rate
def collect_user_data():
print("\nEnter personal information:")
name = input("Full Name: ")
national_id = input("National ID: ")
sector = input("Employment Sector: ")
monthly_salary = float(input("Monthly Salary: "))
return {
"name": name,
"national_id": national_id,
"sector": sector,
"monthly_salary": monthly_salary
}
def get_loan_details():
print("\nLoan Details:")
loan_amount = float(input("Desired Loan Amount: "))
def main():
borrowers = []
for i in range(num_borrowers):
print(f"\n--- Borrower {i + 1} ---")
user_data = collect_user_data()
loan_amount, duration = get_loan_details()
if interest_choice == '1':
monthly_payment, total_interest =
calculate_simple_interest(loan_amount, duration, annual_interest_rate)
interest_type = "Simple"
else:
monthly_payment, total_interest =
calculate_compound_interest(loan_amount, duration,
annual_interest_rate)
interest_type = "Compound"
borrower_info = {
"user_data": user_data,
"loan_amount": loan_amount,
"duration": duration,
"monthly_payment": monthly_payment,
"total_interest": total_interest,
"annual_interest_rate": annual_interest_rate,
"interest_type": interest_type
}
borrowers.append(borrower_info)
if __name__ == "__main__":
main()
Explanation of Python program :
Function: collect_user_data():
def collect_user_data():
return {
"name": name,
"national_id": national_id,
"sector": sector,
"monthly_salary": monthly_salary
}
Function: get_loan_details():
def get_loan_details():
print("\nLoan Details:")
while True:
duration = int(input("Loan Duration (months): "))
if duration in [12, 24, 36, 48, 60]:
break
else:
print("Invalid duration. Please choose 12, 24, 36, 48, or 60
months.")
Function: calculate_simple_interest()
Function: calculate_compound_interest()
while True:
interest_choice = input("Enter 1 or 2: ")
if interest_choice in ['1', '2']:
break
else:
print("Invalid choice. Please enter 1 or 2.")
for i in range(num_borrowers):
if interest_choice == '1':
monthly_payment, total_interest =
calculate_simple_interest(loan_amount, duration, annual_interest_rate)
interest_type = "Simple"
else:
monthly_payment, total_interest =
calculate_compound_interest(loan_amount, duration,
annual_interest_rate)
interest_type = "Compound"
borrower_info = {
"user_data": user_data,
"loan_amount": loan_amount,
"duration": duration,
"monthly_payment": monthly_payment,
"total_interest": total_interest,
"annual_interest_rate": annual_interest_rate,
"interest_type": interest_type
}
borrowers.append(borrower_info)
// All above to Prints formatted loan and personal info for each
borrower.
if __name__ == "__main__":
main()
// Ensures the main() function runs only when the script is executed
directly, not when imported as a module.