0

So this program is supposed to ask for three numbers (R,G,B), that are larger than one and less than 255, and if they are larger than 255 or less than 0 it's supposed to print "R/G/B number is incorrect", but if it is larger than 0 and less than 255, it's supposed to output nothing. My problem is that no matter what number I input, it just prints the "R/G/B number is incorrect" phrase anyways.

Code (python)

r = input("Enter the red: ")
g = input("Enter the green: ")
b = input("Enter the blue: ")

if (r < 0 or r > 255):
    print("Red number is incorrect.")

if (g < 0 or g > 255):
    print("Green number is incorrect.")

if (b < 0 or b > 255):
    print("Blue number is incorrect.")

Some examples of output:

Enter the red: 20
Enter the green: 300
Enter the blue: -1
Red number is incorrect.
Green number is incorrect.
Blue number is incorrect.

or

Enter the red: 20
Enter the green: 20
Enter the blue: 20
Red number is incorrect.
Green number is incorrect.
Blue number is incorrect.
Лев
  • 11
  • 1

1 Answers1

2

You are not converting them to numbers using g = int(input(...))

This should resolve the problem.

Note: in your example, it is comparing strings to numbers, which obviously doesn't work.

Larry the Llama
  • 958
  • 3
  • 13