我如何编写一个算法来读取三个数字并按 python 中的升序打印出来
How do i write an algorithm that reads three numbers and prints them out in ascending order in python
我如何编写一个算法来读取三个数字并按 python 中的升序打印出来。请帮助这是我到目前为止所尝试的我希望你们能帮助我谢谢,这是使用 python 并且我是编程新手。我不知道如何做它所说的升序部分。
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:
print("")*
根据您的代码,下面的代码将按升序打印数字一和二。我建议你尝试完成三个元素的代码。
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:
print(one, two)
else:
print(two, one)
你的举动...
你可以使用 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)
如果您需要使用 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)
我如何编写一个算法来读取三个数字并按 python 中的升序打印出来。请帮助这是我到目前为止所尝试的我希望你们能帮助我谢谢,这是使用 python 并且我是编程新手。我不知道如何做它所说的升序部分。
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:
print("")*
根据您的代码,下面的代码将按升序打印数字一和二。我建议你尝试完成三个元素的代码。
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:
print(one, two)
else:
print(two, one)
你的举动...
你可以使用 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)
如果您需要使用 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)