Reputation: 13
I'm a beginner in python, and I'm trying to solve a problem to practice my knowledge to get further. I'm facing a problem. In nextday = nextday *(10/100)
The problem that I'm trying to solve is:
"As a future athlete you just started your practice for an upcoming event. Given that 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 for you to finally reach the required distance for the event, if you increase your distance each day by 10% from the previous day. Print one integer representing the number of days to reach the required distance."
I've tried to set nextday = nextday * 0.10
but it doesn't run. I'm not receiving an error when I'm doing that, but when I submit the two inputs that I have and then nothing happen. The plus sign works but not multiplication.
firstday = float(input("How many miles you will run the first day? "))
event = float(input("How many miles is the event? "))
nextday = firstday
days = 0
while firstday <= event:
nextday = nextday * (10/100)
firstday = nextday
days = days + 1
print(days)
Upvotes: 0
Views: 292
Reputation: 663
You're taken into what is called infinite loop where end condition of the while loop is never met.
firstday = float(input("How many miles you will run the first day? "))
event = float(input("How many miles is the event? "))
nextday = firstday
days = 0
while firstday <= event:
nextday = nextday * (10/100) # next day becomes 1/10 of next day so it never increases
firstday = nextday
days = days + 1
print(days)
Correct code in increasing would be:
firstday = float(input("How many miles you will run the first day? "))
event = float(input("How many miles is the event? "))
nextday = firstday
days = 0
while firstday <= event:
nextday = nextday * 1.1 # 10% increace! not tenth of previous value
firstday = nextday
days = days + 1
print(days)
Upvotes: 2