+ 1
I need help on python with the finance app practice
Iâve been stuck in a loop and canât figure out where did I go wrong https://sololearn.com/compiler-playground/cXT9pOcSCq6a/?ref=app
5 Answers
+ 10
Nicot
# Convert the user input into a float value and update the variable
* you forgot to put savings inside the parentheses
f_savings = float(savings)
# Convert the balance into a string and update the variable
* you hard-coded the 157.50 as the balance verses letting the code pass the variable balance value
s_balance = str(balance)
+ 4
Awesome, it worked. Thank you!
+ 3
You're welcome Nicot
+ 2
you're getting a syntax error... check over your code for anything missing...
and are you wanting input twice?
0
def main():
compounder()
def compounder():
new = '\n'
p = float(input()) # principal, initial balance
r = float(input()) # percent form, e.g. input for 2.5%: 2.5
y = float(input()) # years
a = p * (1 + r / 100)**y # amount = principle(1 + rate/100)^years
g = a - p # net gain
if y <= 1:
print(f'Initial Balance: ${p:,.2F}{new}Rate: {r:,.2F}%{new}Balance at {y:,.2F} Year: ${a:,.2F}{new}Gain: ${g:,.2f}')
elif y > 1:
print(f'Initial Balance: ${p:,.2F}{new}Rate: {r:,.2F}%{new}Balance at {y:,.2F} Years: ${a:,.2F}{new}Gain: ${g:,.2f}')
else:
print('There must be a strategic error on your end!')
if __name__=='__main__':
main()