+ 4

Cell Growth - Python Beginners - while loops

I am pretty new to programming. So, I know this question may be extremely simple for most people, but I am really confused on this problem bellow it. And I wonder if someone could help me to understand it better. I would like to know What is the "counter" for in this problem? and why should one be added to the days? (line 11) Thank you :) __________________________________________________________ PROBLEM Imagine you are a scientist looking at a new type of cell under the microscope. This type of cell divides itself into 2 daughter cells every 24 hours, meaning that the cell population duplicates every day. Task Complete the code to take the initial cell population and the number of days you are observing the cells to calculate the cell population at the end of each day in the following format img-component ____________________________________ # take the initial cell population as input cells = int(input()) # take the number of days as input days = int(input()) # initialize the day counter counter = 1 #complete the while loop while counter < days + 1: cells = cells*2 # Daily message print("Day " + str(counter) + ": " +str(cells)) counter += 1

12th Jul 2023, 6:03 PM
Karine Magalhaes Heidgerken
Karine Magalhaes Heidgerken - avatar
3 ответов
+ 6
The idea of the solution is to imitate as described in the task. The counter is the day number. And each day the cells will be duplicated. You set the counter respectively your day to 1 and the number of cells from input. Then you double the cellls in the while loop and add 1 to the counter („day number“) and so each day will be closed. You do that as often as received number of days.
12th Jul 2023, 6:51 PM
JaScript
JaScript - avatar
+ 1
# take the initial cell population as input cells = int(input()) # take the number of days as input days = int(input()) # initialize the day counter counter = 1 #complete the while loop while counter < days + 1: cells = cells * 2 # Daily message print("Day " + str(counter) + ": " +str(cells)) counter += 1
30th Jan 2024, 5:37 AM
Pablo Altieri
Pablo Altieri - avatar
0
i was perplexed by this solution that was 'given' to us because to me the counter is well, counterintuitive and unnecessary. what i would have done is instead use a for loop on the days and do the cell calculation iterating each day-1 until day 0 making counters or adding days unnecessary.
30th Dec 2023, 5:23 PM
Just Mad Jestic
Just Mad Jestic - avatar