Morning jog. As a future athlete, you are training for an upcoming event. On the first day, you run x miles, and by the event, you must be able to run y miles. Calculate the number of days required to reach the required distance for the event if you increase your distance by 10% each day from the previous day. Print one integer representing the number of days to reach the required distance.
|
x = float(input()) y = float(input()) days = 1 while x < y: x *= 1.1 days += 1 print(days) |
Explanation of the Code
- Reading Input:
x = float(input())
y = float(input())
- The
input()
function reads lines of text from the user.
- The
float()
function converts these inputs to floating-point numbers and stores them in the variables x
and y
.
- Calculating the Number of Days:
days = 1
while x < y:
x *= 1.1
days += 1
- Initialize
days
to 1 because you start running on the first day.
- Use a
while
loop to keep increasing x
by 10% each day (i.e., x *= 1.1
) until x
is greater than or equal to y
.
- Increment the
days
counter by 1 each iteration of the loop.
- Printing the Number of Days:
- Once the loop completes, print the value of
days
.