简体   繁体   中英

Why does does the body of my while statement not print even though the condition is true in python

I am writing a program that displays the numbers where the user decides the numbers per line, but the number has to be between 10 and 30 although for whatever reason the while statement doesn't execute even if the condition is true. for example if I input the number 5 it should output "Number must be between 10 and 30" but instead it outputs 1 to 1000 with 5 numbers per line.

Below is my code, any assistance you can provide would be greatly appreciated

count = 0
X = int(input('please enter a number:'))

while X <=10 and X >=30:
        print('Number must be between 10 and 30')
    
else:
    for number in range (1, 1000, 1):
            print(number,' ', end = '')
            count = count + 1
            if count == X:
                print()
                count = 0

Please modify the condition in while loop by using "OR" logical operator,because the error message needs to be printed for either number<=10 or number>=30 conditions.

while X <=10 or X >=30: print('Number must be between 10 and 30')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM