So I'm trying to make a list starting from day one and moving onward, however every time i run the code it starts from the days the user inputs. It's probably an easy fix but I'm stumped. Any help would be appreciated!
orig = int(input("Enter the starting number of organisms: "))
days = int(input("Enter the number of days: "))
increase = float(input("Enter the daily population increase: "))
for i in range(days):
orig = orig * (1 increase)
days = days 1
print(f'After {days} days there are {orig:.6f} organisms')
CodePudding user response:
then why not using i as the day counter:
orig = int(input("Enter the starting number of organisms: "))
days = int(input("Enter the number of days: "))
increase = float(input("Enter the daily population increase: "))
for i in range(days):
orig = orig * (1 increase)
print(f'After {i 1} days there are {orig:.6f} organisms')
CodePudding user response:
days = int(input("Enter the number of days: "))
increase = float(input("Enter the daily population increase: "))
for i in range(days):
orig = orig * (1 increase)
days = days 1
print(f'After {i 1} days there are {orig:.6f} organisms')
CodePudding user response:
You are forgetting to use i
which is increasing in the way you would want days
to increase:
orig = int(input("Enter the starting number of organisms: "))
days = int(input("Enter the number of days: "))
increase = float(input("Enter the daily population increase: "))
# Starting the range from 1 makes more sense
for i in range(1, days 1):
orig *= (1 increase)
print(f'After {i} days there are {orig:.6f} organisms')
Enter the starting number of organisms: 1
Enter the number of days: 5
Enter the daily population increase: 1
After 1 days there are 2.000000 organisms
After 2 days there are 4.000000 organisms
After 3 days there are 8.000000 organisms
After 4 days there are 16.000000 organisms
After 5 days there are 32.000000 organisms
CodePudding user response:
Changed code to track day number
orig = int(input("Enter the starting number of organisms: "))
days = int(input("Enter the number of days: "))
increase = float(input("Enter the daily population increase: "))
for i in range(days): # will take on the values 0 to days -1
orig = orig * (1 increase)
day_number = i 1 # create a day number which will have the value 1 to days
print(f'After {day_number} days there are {orig:.6f} organisms')
Trial run
Enter the starting number of organisms: 5
Enter the number of days: 5
Enter the daily population increase: .5
After 1 days there are 7.500000 organisms
After 2 days there are 11.250000 organisms
After 3 days there are 16.875000 organisms
After 4 days there are 25.312500 organisms
After 5 days there are 37.968750 organisms