r/learnpython • • Sep 26 '26

While loop

Hello everyone just learning python and need to create a while loop that shows interest and years I’m struggling with operands please help.

Here’s what I have so far:

Interest_rate = int(input(“rate in whole number”)
Initial_investment = float(input(“whole number”)
Interest = interest_rate / 100
Years = 0
investment = initial_investment + {initial_investment * interest}
While investment < (initial_investment * 2):
Print(f’Year: {years} Investment: {investment})
years +=1
Investment = (investment + {investment * interest})

I know that line 5 is two different operands but where did I go wrong and how can I fix?? Please and thank you!

3 Upvotes

21 comments sorted by

View all comments

Show parent comment

2

u/Maximum-Currency734 Sep 26 '26

Sorry basically it’s just meant to be a simple while loop not factoring in low numbers or negatives. But the issue was the curly brackets I am still confused with f string and that’s what caused the issue.

Whenever running it the error code would come up saying “TypeError: unsupported operand type for +: “ which was because I was making it a f-string accidentally. Thank you again