cshiv
November 2, 2025, 4:19pm
1
Tell us what’s happening:
I think my code is right, but the modulus statement never runs. What’s happening?
Your code so far
def infected(days):
computers = 1
i = 0
while i < days:
computers *= 2
if i%3 == 0:
computers = computers - round(computers*0.2)
i+=1
return computers
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Infected
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-11-02
ILM
November 2, 2025, 4:46pm
2
the if execute, the issue you have is a different one: you are never curing enough computers
Round the number of patched computers up to the nearest whole number.
Also: you are doubling infected computers also on day 0, which is not what should happen
You have already handled Day 0 by setting computers to 1, but by then starting your loop counter at 0, you are throwing everything off. And round isn’t that same as rounding up to the nearest integer.
cshiv
November 2, 2025, 7:49pm
4
thats why i used less than
ILM
November 2, 2025, 9:07pm
5
that works for the while, not for counting each third day at which to calculate the patched computers
cshiv
November 3, 2025, 12:41am
6
i swapped the i in the modulus with i+1 and only the last one is unsatisfied
ILM
November 3, 2025, 9:25am
7
did you fix the rounding?
cshiv
November 4, 2025, 12:47pm
8
I didn’t change anything, except for what I said I changed. Also, the last value is off by a lot
ILM
November 4, 2025, 1:44pm
9
well, why don’t you try with fixing the rounding? you are not rounding up to the nearest integer