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?

2 Answers

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.

0 votes
by (1.3k points)

If you want to check multiple conditions within the loop in Python , you implement conditional statements like, if,else and elif. For the case of printing a message when “a” is greater than 10 but less than 20.

Code: 

a = 0

while a < 20:

    if a < 10:

        print("a is Less than 10")

    elif 10 < a < 20:

        print("a is Greater than 10, but less than 20.")

     a = a + 1

Related questions

0 votes
1 answer
asked Jul 30, 2019 in SQL by Tech4ever (20.3k points)
0 votes
3 answers

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...