Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in BI by (4k points)

I have this code I'm just playing with, As I'm new to python, which is this:

a = 0
while a < 10:
    a = a + 1
    print("A is Less than 10")

I want to add some more code that says: If a is more than 10 but less than 20, print this:
I tried:

a = 0
while a < 10:
    a = a + 1
    print("A is Less than 10")
while a < 20:
    a = a + 1
    print("A is More than 10, but less than 20.")

But all that does is print "A is more than 10, but less than 20"
Basically, is there a "Less than but greater than" function in python?

1 Answer

0 votes
by (8.7k points)

Python support the below code:

while 18 < X < 26:

   x=x+1

 print("X is Less than 20")

Using for loop:

for x in range(12, 22):

 

Want to check for a single number without a loop

if 10 < X < 20: 

 print(“X is Greater than 10 and less than 20”)

 

Kindly take care of boundary conditions and looping in your code as the loop first executed will set the value of X.

Related questions

0 votes
1 answer
asked Dec 9, 2020 in BI by Chris (11.1k points)
0 votes
0 answers

Browse Categories

...