0

I am trying to write a function in Python that would return a colour value after evaluating to a user value. This what I have tried, however, I am not get what I expect, a single colour. I am getting a list of colours. I am new to programming.

uservalue = 100000

def colour(m,i):
    if uservalue > (m + i):
        clrs == "red"                  
    elif uservalue < (m - i):
        clrs == "blue"              
    else:
        clrs == "white"         
    return clrs

to test I use this input:

colour(20000, 3000)  

output:

['red', 'red', 'red', 'white', 'white', 'white', 'white']

I was looking for one colour returned after evaluation.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
Celtis
  • 9
  • 1

2 Answers2

0
uservalue = 100000

def colour(m,i):
    if uservalue > (m + i):
        clrs = "red"                  
    elif uservalue < (m - i):
        clrs = "blue"              
    else:
        clrs = "white"         
    return clrs

print(colour(20000, 3000))

output will be: red

Shivam Seth
  • 677
  • 1
  • 8
  • 21
0

you are almost there. replace == with =. == is referred when checking equality and = is referred when assigning a value to a variable. try below code.

uservalue = 100000

def colour(m,i):
    if uservalue > (m + i):
        clrs = "red"                  
    elif uservalue < (m - i):
        clrs = "blue"              
    else:
        clrs = "white"         
    return clrs