Advertisement
pacho_the_python

loans

Dec 28th, 2023
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. def calculate_simple_interest(a, b, c):
  2.     result = a + b + c
  3.     return result
  4.  
  5.  
  6. def calculate_compound_interest(a, b, c):
  7.     result = a - b - c
  8.     return result
  9.  
  10.  
  11. def calculate_loan_payment(a, b, c):
  12.     result = a * b * c
  13.     return result
  14.  
  15.  
  16. def calculate_future_value_of_savings(a, b, c):
  17.     result = a / b / c
  18.     return result
  19.  
  20.  
  21. def goodbye():
  22.     return 'Goodbye'
  23.  
  24.  
  25. def main_menu_options():
  26.     options = [
  27.         'Main Menu:',
  28.         ' 1.Calculate Simple Interest',
  29.         ' 2.Calculate Compound Interest',
  30.         ' 3.Calculate Loan Payment',
  31.         ' 4.Calculate Future Value of Savings',
  32.         ' 5.Quit'
  33.     ]
  34.     return '\n'.join(options)
  35.  
  36.  
  37. def main_menu(customer_input):
  38.     possible_options = {
  39.         '1': lambda a, b, c: a + b + c,
  40.         # '1': calculate_simple_interest,
  41.         '2': calculate_compound_interest,
  42.         '3': calculate_loan_payment,
  43.         '4': calculate_future_value_of_savings,
  44.         '5': goodbye,
  45.     }
  46.  
  47.     while True:
  48.  
  49.         if customer_input not in possible_options:
  50.             print('Value is incorrect. Enter new value.')
  51.         else:
  52.             if customer_input == '5':
  53.                 print(goodbye())
  54.                 break
  55.             value_1 = float(input())
  56.             value_2 = float(input())
  57.             value_3 = float(input())
  58.             calculation_result = possible_options[customer_input](value_1, value_2, value_3)
  59.             print(f"{calculation_result:.2f}")
  60.             customer_input = input('Do you want to perform another calculation? (yes/no): ')
  61.             possible_chooses = ['yes', 'no']
  62.             while True:
  63.                 if customer_input not in possible_chooses:
  64.                     print('Enter correct value! (yes/no) ')
  65.                     customer_input = input()
  66.                 else:
  67.                     break
  68.  
  69.             if customer_input == 'no':
  70.                 print(goodbye())
  71.                 break
  72.             else:
  73.                 print(main_menu_options())
  74.  
  75.         customer_input = input()
  76.  
  77.  
  78. print(main_menu_options())
  79. customer_choose = input()
  80. main_menu(customer_choose)
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement