Guest User

Untitled

a guest
Jan 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. '''Tengo esta tarea, se definieron 3 variables (balance, annualInterestRate y monthlyPaymentRate). Es para calcular cuanto se habra pagado de un prestamo al final de un aƱo, si se paga con la tasa mas baja. En este caso los valores de prueba son: balance = 5000, annualInterestRate = 0.18 y monthlyPaymentRate = 0.02
  2. El output es asi:
  3. Month: 1 (para cada mes)
  4. Minimum monthly payment: 96.0 (para cada mes)
  5. Remaining balance: 4784.0 (para cada mes)
  6. Total paid: 96.0 (al final del programa)
  7. Remaining balance: 4784.0 (al final del programa)
  8. En el idle me corre bien y genera los datos pero en el sistema de edx me da error.'''
  9.  
  10. #Opcion1
  11. month = 1
  12. totalPaid = 0
  13. for month in range(1,12):
  14.     minMonthlyPayment = monthlyPaymentRate * balance
  15.     interest = (balance - minMonthlyPayment) * (annualInterestRate / 12)
  16.     updatedMonthlyBalance = balance + interest - minMonthlyPayment
  17.     print('Month: ' + str(month))
  18.     print('Minimun monthly payment: ' + str(round(minMonthlyPayment,2)))
  19.     print('Updated balance each month: ' + str(round(updatedMonthlyBalance,2)))
  20.     month += 1
  21.     totalPaid += minMonthlyPayment
  22.     balance = updatedMonthlyBalance
  23. print('Total paid: ' + str(round(totalPaid, 2)))
  24. print('Remaining balance: ' + str(round(updatedMonthlyBalance, 2)))
  25.  
  26. #Opcion2
  27. def ccbalance(balance, annualInterestRate, monthlyPaymentRate):
  28.     month = 1
  29.     totalPaid = 0
  30.     while month < 13:
  31.         minMonthlyPayment = monthlyPaymentRate * balance
  32.         interest = (balance - minMonthlyPayment) * (annualInterestRate / 12)
  33.         updatedMonthlyBalance = balance + interest - minMonthlyPayment
  34.         print('Month: ' + str(month))
  35.         print('Minimun monthly payment: ' + str(round(minMonthlyPayment,2)))
  36.         print('Updated balance each month: ' + str(round(updatedMonthlyBalance,2)))
  37.         month += 1
  38.         totalPaid += minMonthlyPayment
  39.         balance = updatedMonthlyBalance
  40.     print('Total paid: ' + str(round(totalPaid, 2)))
  41.     print('Remaining balance: ' + str(round(updatedMonthlyBalance, 2)))
Add Comment
Please, Sign In to add comment