你可以使用 sorted(),但首先你将数字保存在一个列表中,试试这个:
nums = []
one = nums.append(float(input("Please input a number : ")))
two = nums.append(float(input("Please input a second number : ")))
three = nums.append(float(input("Please input a third number : ")))
for num in sorted(nums):
print (num)
sorted() - Python 文档
如果您需要使用 if 和 else 语句,您应该考虑输入数字的所有组合并评估它,试试这个:
one = float(input("Please input a number : "))
two = float(input("Please input a second number : "))
three = float(input("Please input a third number : "))
if one < two and three < two:
if one > three:
print(three, one, two)
else:
print(one, three, two)
elif one < three and two < three:
if one > two:
print(two, one, three)
else:
print(one, two, three)
elif two < one and three < one:
if three > two:
print(two, three, one)
else:
print(three, two, one)
else:
print(one, two, three)