This question already has an answer here:
this is only calculating the future value(1st if-statement), regardless of what the user input is, how do I fix this issue? I've tried nesting the if statements, as well as changing the while loop to an if statement. Is the issue in the if-statement, while-loop, parameter passing, or an issue with the scope of variables?
user_menu = ['F','P','Q','M','f','p','q','m']
def displayMenu():
menu_display = ''' Welcome to Jane Doe's Financial Calculator
You may use this handy tool in order to calculate your expenses
Enjoy :)
F = Future Value
P = Present Value
M = Monthly Payments
Q = Quit'''
print(menu_display)
print()
def calculateFutureValue(A,r,t):
future_value= A*(1+r)**t
return future_value
def calculatePresentValue(A2,r2,t2):
present_value= A2*(1+r2)**(-t2)
return present_value
def calculateMonthlyPayment(loan_amount,r,t):
monthly_payment= (loan_amount*r3/12*(1+r3/12)**t3*12)/((1+r3/12)**(t3*12)-1)
return monthly_payment
displayMenu() #calls func to display menu to user
user_choice = str(input('Please select an option from the provided menu: '))
while user_choice != 'Q' or 'q':
if user_choice == 'F'or'f':
print('You are using the Future Value Calc!')
A = float(input('Please enter an amount in USD: '))
r = float(input('Please enter an interest rate: '))
t = float(input('Please enter an amount of time in years: '))
calculateFutureValue(A,r,t)
print('The future value is',calculateFutureValue(A,r,t))
elif user_choice == 'P'or'p':
print('You are using the Present Value Calc!')
A2 = float(input('Please enter an amount in USD: '))
r2 = float(input('Please enter an interest rate: '))
t2 = float(input('Please enter an amount of time in years: '))
calculatePresentValue(A2,r2,t2)
print('The present value is',calculatePresentValue(A2,r2,t2))
elif user_choice == 'M'or'm':
print('You are using the Monthly Payment Calc!')
loan_amount=float(input('Please enter loan amount in USD: '))
r3 = float(input('Please enter an interest rate: '))
t3 = float(input('Please enter an amount of time in years: '))
calculateMonthlyPayment(loan_amount,r3,t3)
print('The montly payment is',calculateMonthlyPayment(loan_amount,r3,t3))
elif user_choice not in user_menu:
print('Please only use the provided menu options!')
calculateFutureValue(A,r,t)
calculatePresentValue(A,r2,t2)
calculateMonthlyPayment(loan_amount,r3,t3)
Aucun commentaire:
Enregistrer un commentaire