Python while条件循环不';我救不了自己

Python while条件循环不';我救不了自己,python,python-3.x,while-loop,Python,Python 3.x,While Loop,首先,我想说我最近刚开始编程,所以我不是很好。这是我的问题: x = int(input("Write a number between 1-100: ")) while x > 100: x = int(input("The number must be less than 101: ")) while x < 1: x = int(input("The number must be higher than 0: ")) else: print ("The

首先,我想说我最近刚开始编程,所以我不是很好。这是我的问题:

x = int(input("Write a number between 1-100: "))
while x > 100:
    x = int(input("The number must be less than 101: "))
while x < 1:
    x = int(input("The number must be higher than 0: "))
else:
    print ("The number is:",x)
我基本上不希望用户能够写出大于100或小于1的数字


很抱歉解释得不好,但我已经尽了最大努力,最近又开始编程了。

使用逻辑
在单个
中测试这两种情况,同时

while not 1 <= x <= 100:  
    x = int(input("The number must be in range [1, 100]: "))

而非1使用逻辑
在单个
中测试两种情况:

while not 1 <= x <= 100:  
    x = int(input("The number must be in range [1, 100]: "))
虽然在Python中不是1,但与其他编程语言不同,像a,而
-循环如下:

x = int(input("Write a number between 1-100: "))
while not 1 <= x <= 100:
    x = int(input("The number must be in the range 1-100: "))
else:
    print ("The number is:", x)
x=int(输入(“写一个介于1-100之间的数字:”)
虽然Python中不是1,但与其他编程语言不同的是,像a,而
-循环如下:

x = int(input("Write a number between 1-100: "))
while not 1 <= x <= 100:
    x = int(input("The number must be in the range 1-100: "))
else:
    print ("The number is:", x)
x=int(输入(“写一个介于1-100之间的数字:”)

而不是1我会这样做:

x = int(input("Enter a number in the range [1, 100]: "))
while not (1 <= x <= 100):
    x = int(input("That number isn't in the range [1, 100]!: "))
else:
    print ("The number is:",x)
x=int(输入(“输入[1100]:”范围内的数字)

虽然不是(1我会这样做:

x = int(input("Enter a number in the range [1, 100]: "))
while not (1 <= x <= 100):
    x = int(input("That number isn't in the range [1, 100]!: "))
else:
    print ("The number is:",x)
x=int(输入(“输入[1100]:”范围内的数字)

而不是(1我只想添加另一种编写wile循环的方法:
而不是1@Matthias。是的,忘了Python允许这种条件。将编辑帖子。谢谢:)我只想添加另一种编写wile循环的方法:
而不是1@Matthias。是的,忘了Python允许这种条件。将编辑帖子。谢谢:)我真的很抱歉,但我不明白(1@Weriton它是如何工作的,因为Python太棒了!:)说真的,我不知道为什么所有语言都没有这个。但无论如何,这只是最直观的方式来写,而条件。在英语中,当数字“不在1和100之间(包括1和100之间)”时,您希望循环。在这种情况下,简单的英语可以很好地翻译成Python。很抱歉,在我看来,这个命令告诉我的是,虽然1不小于或等于x,x也不小于或等于100。你明白我的意思吗?再次感谢:)@Weriton是的,我明白你的意思,因为你是绝对正确的。这正是while条件所做的。xDI真的很抱歉,但我不明白是谁(1@Weriton它工作,因为Python太棒了!:)说真的,我不知道为什么所有语言都没有这个。但无论如何,这只是最直观的方式来写,而条件。在英语中,当数字“不在1和100之间(包括1和100之间)”时,您希望循环。在这种情况下,简单的英语可以很好地翻译成Python。很抱歉,在我看来,这个命令告诉我的是,虽然1不小于或等于x,x也不小于或等于100。你明白我的意思吗?再次感谢:)@Weriton是的,我明白你的意思,因为你是绝对正确的。这正是while条件所做的。除息的