Nov-12-2018, 02:25 AM
Your current code has syntax errors. In the first version on line 4, you are checking if cpu equals a range object; this is failing for two reasons. First, cpu is a number, not a range object so it will never be equal. The intent is to check if cpu is within the range, not that it's equal to the range. There are two ways to write this:
def getvalue(cpu): if cpu <= 300: value = 1 elif cpu in range(301,600): value = 2 else: value = 3 return valueor
def getvalue(cpu): if cpu <= 300: value = 1 elif 301 <= cpu <= 600: value = 2 else: value = 3 return valueOn a side note, a random number between 1 and 900 is excessive. You truly only need one through three since there are only three possibilities.