I’m completely stumped on this level. It seems like a massive jump up in complexity without a lot of good explanation about what this new mod() function is actually doing. I’m just staring blankly at the screen, then watching as my hero dies in slow motion. Any help much appreciated.
if n >= 30:
return n - 30
# This function should return a value from 0 to 40 (0 <= n < 40)
# Use an if-statement to return the correct value.
if n <= 40:
# You don't need to change the following code:
time = hero.time
x = mod30(time) + 25
y = mod40(time) + 10
In terms of solving the level, the code for the function for mod40 is nearly identical to the code for function mod30.
You’ve just made me look back at the level, and I don’t think it’s particularly useful for teaching. Apart from anything else, the function doesn’t always calculate the modulus (it works for the numbers being used in the level, but it doesn’t work for bigger numbers).
To get a better understanding of what it’s trying to do, here’s nearly the same code (I changed one word, and then called the function to find the modulus of 278):
while n >= 30:
n = n - 30
answer = mod30(278)
Copy the code into http://www.pythontutor.com and click ‘Visualise execution’ - you can then go through it step by step.
Thanks for another great reply. I just got past the level by tracking down the correct answer from somewhere. I still dont really understand it, even though i understand the concept of modulus and remainders when ive heard it talked about in other places. Hopefully i can understand how the CoCo system uses it better by progressing through.
Thanks a lot for helping. After taking a week away and coming back to it, and applying everyones ideas i managed to solve the level!