-4
def valMap(x, in_min, in_max, out_min, out_max):
    return ((x - in_min) * (out_max - out_min)) // (in_max - in_min) + out_min


def limit(self, input):

    if -0.2 <= input <= 0.2:
        input = 192
    if input < -0.2:
        input = valMap(input, -0.2, -1, 138, 192)
    if input > 0.2:
        input = valMap(input, 0.2, 1, 192, 242)
    return input

The input's value ranges from -1 to +1 float. This only works as expected in the last if statement. All other if statements throw out strange numbers.

This did work in Python2.

Thank you

user3603948
  • 153
  • 3
  • 12
  • 3
    please provide sample inputs and wrong + expected outputs – Neapolitan May 20 '16 at 02:01
  • 1
    "strange numbers" doesn't tell us anything. What is an input that you find works differently in Python2 and Python3, and what is the output you expect (and get in Python2) and what is the output in you're getting instead in Python3? – Amadan May 20 '16 at 02:02
  • 2
    You probably mean to use elif in the limit function. Either that or return statements in each branch. That would explain why only the last one is working. – Neapolitan May 20 '16 at 02:02

1 Answers1

1

This doesn't look like it has anything to do with the Python version. Are you sure your if conditions are dependent ? From what I see, you are calling the valMap function again in the last if statement depending upon the result of the first function call. Did you mean to use elif instead ?

mng
  • 393
  • 2
  • 10