Search code examples
pythonpython-3.xsyntaxoperator-keywordalgebra

Python 3.4 - Struggling with a basic program that outputs x if a number from 0-9 is typed


This is just example code for a larger program I'm making, but I can't seem to get it to work. Basically, Python recognises the <= as incorrect syntax, but I'm failing to see how. What is the correct way to write this line on the program?

number1 = int(input())

if number1 >= 0 and <= 9:
    print("x")
else:
    print("y")

Any help is appreciated.


Solution

  • You can do as follows:

    if  0 <= number1 <= 9:
        print("x")
    else:
        print("y")