Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module help
#11
It looks like you created two accounts. I've merged the post from the second one, and banned the first one. (Why do we think it's a duplicate? Because it was accessed from the same browser, same IP address, is almost a perfect-copy paste, and "bot" is in the name.)

I only banned the second account. Please don't do anything that would encourage an IP ban, or anything more serious.

As for your question - you've received a great deal of help in this thread. If you're still stuck, elaborate as completely as concisely as possible and you'll likely get good help.
Reply
#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
#13
Another hint: Your code goes to zero when it gets to 89. But you don't want that. You want it to go to zero when it goes one past 89. That is, you want it to go to zero when it gets to 90, not when it gets to 89. How might you change your code to fix that?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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