sales = 1000
#def commissionRate():
if (sales < 10000):
print("da")
else:
if (sales <= 10000 and >= 15000):
print("ea")
Syntax error on the if (sales <= 10000 and >= 15000): line. Particularly on the equal signs.
sales = 1000
#def commissionRate():
if (sales < 10000):
print("da")
else:
if (sales <= 10000 and >= 15000):
print("ea")
Syntax error on the if (sales <= 10000 and >= 15000): line. Particularly on the equal signs.
You need to compare sales against the second condition also:
In [326]:
sales = 1000
#def commissionRate():
if (sales < 10000):
print("da")
else:
if (sales <= 10000 and sales >= 15000):
print("ea")
da
you need this:
if (sales <= 10000 and sales >= 15000):
^^^^ sales here
Additionally you don't need parentheses () around the if conditions:
if sales <= 10000 and sales >= 15000:
works fine
You could rewrite it to the more compact:
In [328]:
sales = 1000
if sales < 10000:
print("da")
else:
if 10000 <= sales <= 15000:
print("ea")
da
so if 10000 <= sales <= 15000: works also, thanks @Donkey Kong
Additionally (thanks @pjz) and nothing to do with code is that logically sales cannot be both less than 10000 and greater than 15000.
So even without the syntax errors that condition will never be True.
You wanted if sales > 10000 and sales <= 15000: or if 10000 <= sales <= 15000: which maybe clearer for you
Just to expand on the if 10000 <= sales <= 15000: syntax (thanks @will for the suggestion), in python one can perform math comparisons lower_limit < x < upper_limit also explained here that are more natural than the usual if x > lower_limit and x < upper_limit:.
This allows comparisons to be chained, from the docs:
Formally, if
a,b,c, ...,y,zare expressions andop1,op2, ...,opNare comparison operators, thena op1 b op2 c ... y opN zis equivalent toa op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.
if (10000<= sales <= 15000) too maybe?lower < x < upper works by expanding it into a chain of comparisons, which means you can do other stuff too which can allow some other stuff you wouldn't normally see in standard maths comparisons.