Beginner · While loops · 88 of 264
Money doubles
Money in a bank grows by a fixed percentage every year. How many whole years until it has at least doubled?
Input: the yearly interest in percent (a whole number above 0). Output: the number of years.
Examples
Input
10
Output
8
Input
100
Output
1
Input
3
Output
24
One more test checks other inputs when you press Check.
Stuck? The idea behind while loops
A while loop repeats as long as its condition is true: use it when you don't know in advance how many times.
Something inside the loop must change, so the condition becomes false in the end.
n = int(input())
digits = 0
while n > 0:
n //= 10
digits += 1
print(digits)Watch for: If nothing in the loop changes the condition, it never ends and the program is stopped after a few seconds.