How do i write an algorithm that reads three numbers and prints them out in ascending order in python. Please help this is what i have tried so far i hope you guys can help me out thank you, this is using python and i am new to programming. I do not know how to do the part where it says in ascend orders.
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("")*
you can use sorted(), but first you have a save the numbers in a list, try with this:
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 you need use a if and else statement, you should think in all combinations about your input numbers and evaluate this, try with this:
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)