Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module help
#12
It is useful to play with interactive interpreter to get inspiration:

>>> len(range(40, 90))
50
This 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 item
There 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.
Reply


Messages In This Thread
Module help - by wak_stephanie - Jul-22-2018, 10:57 PM
RE: Module help - by micseydel - Jul-27-2018, 03:54 AM
RE: Module help - by perfringo - Jul-27-2018, 07:14 AM
RE: Module help - by ichabod801 - Jul-27-2018, 12:59 PM
RE: Module help - by Larz60+ - Jul-22-2018, 11:17 PM
RE: Module help - by wak_stephanie - Jul-22-2018, 11:33 PM
RE: Module help - by Larz60+ - Jul-22-2018, 11:41 PM
RE: Module help - by ichabod801 - Jul-23-2018, 12:42 AM
RE: Module help - by wak_stephanie - Jul-23-2018, 03:19 AM
RE: Module help - by ichabod801 - Jul-23-2018, 03:25 AM
RE: Module help - by wak_stephanie - Jul-23-2018, 03:34 AM
RE: Module help - by ichabod801 - Jul-23-2018, 01:49 PM
Module help - by stangerbot342 - Jul-26-2018, 09:57 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020