It is useful to play with interactive interpreter to get inspiration:
We see that some values are larger than our scale. There are also negative value. This should drive us towards remainder division.
Let's try it with different values:
We can see pattern here - we stay within 50 range, and all numbers (including negative) are distance from starting point (0).
In spoken language we can spell: needed value is reminder of division of clicks with 50 if said division is equal or large than 0 otherwise it's number of clicks.
To put it in Python we can use conditional expression:
So we may reach to such code:
>>> len(range(40, 90)) 50This is the number what is important in calculations. For simplification of problem we can say that we have scale 0 ... 49.
We see that some values are larger than our scale. There are also negative value. This should drive us towards remainder division.
Let's try it with different values:
>>> 0 % 50 0 >>> 1 % 50 1 >>> 50 % 50 0 >>> 60 % 50 10 >>> 200 % 50 0 >>> -1 % 50 49 >>> -100 % 50 0 >>> -120 % 50 30
We can see pattern here - we stay within 50 range, and all numbers (including negative) are distance from starting point (0).
In spoken language we can spell: needed value is reminder of division of clicks with 50 if said division is equal or large than 0 otherwise it's number of clicks.
To put it in Python we can use conditional expression:
value = item % 50 if item % 50 >= 0 else itemThere are two minor adjustments needed. Our scale starts with 40 therefore we must add it to value like
40 + value
. There are also strings in list but in order to make calculations we need numbers (integers). So we may reach to such code:
clicks = ['0', '49', '74', '51', '-1', '200'] for item in clicks: item = int(item) value = item % 50 if item % 50 >= 0 else item print(f'The temperature is {40 + value}')
Output:The temperature is 40
The temperature is 89
The temperature is 64
The temperature is 41
The temperature is 89
The temperature is 40
To OP: this is provided to help you to understand some basic steps in problem solving. As smart people have said: you should spend 80% of time thinking about your problem and how to solve it and 20% of time writing solution in code.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.