Using < & > (less than and greater than) in an if statement in Jython

I'm writing a small program that requires a few if statements like so:

number=x/(y*y)

if number <5:
  print "blahblahblah"

if number >5 or <10:
  print "blahblahblah"

if number >10.5 or >15.0:
  print "blahblahblah"

if number >15:
  print "blahblahblah"

Basically I'm having trouble with using both > and < in my if statement and can't work out how to say "if less than 4 or more than 5"

When I load the program I get the following error -

Invalid syntax Your code contains at least one syntax error, meaning it is not legal jython.

Any help would be greatly appreciated

Answers


Here you go:

if number > 10 and number < 20 then:
   print "Number between 10 and 20"

Each comparison is an independent expression, combined together with and, or, etc.


As an addition to Paul answer with or, and etc you can use if 5 < number < 10::

if number < 5:
    print("a")

if 5 < number < 10:
    print("b")

if 10 < number < 15:
    print("c")

if number > 15:
    print("d")

You can also use elif (short of else if) and else which I prefer:

if number < 5:
    print("a")
elif number < 10:
    print("b")
elif number < 15:
    print("c")
else:
    print("d")

BTW in your code you used or instead of and.


Need Your Help

Joomla 2.5 ajax file upload

ajax joomla

I want to upload files through a component that I'm developing on Joomla 2.5, I need to support not HTML5 browsers without flash. On Joomla 1.5 I successfully used this method , but on J2.5 after ...