-2

我正在编写一个程序,显示用户决定每行数字的数字,但数字必须在 10 到 30 之间,尽管无论出于何种原因,即使条件为真,while 语句也不会执行。例如,如果我输入数字 5,它应该输出“数字必须在 10 到 30 之间”,而是输出 1 到 1000,每行 5 个数字。

以下是我的代码,您可以提供的任何帮助将不胜感激

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
4

1 回答 1

0

请使用“或”逻辑运算符修改 while 循环中的条件,因为需要为 number<=10 或 number>=30 条件打印错误消息。

而 X <=10 或 X >=30: print('数字必须在 10 和 30 之间')

于 2021-04-08T20:19:35.737 回答