Input three integers x, y, z, please output these three numbers from thesmallestto the largest.
时间: 2023-12-07 08:03:07 浏览: 28
Sure, here's a Python program that takes three integers as input from the user, and outputs them in ascending order:
```python
x = int(input("Enter the first integer: "))
y = int(input("Enter the second integer: "))
z = int(input("Enter the third integer: "))
# Find the smallest number
if x <= y and x <= z:
smallest = x
elif y <= x and y <= z:
smallest = y
else:
smallest = z
# Find the largest number
if x >= y and x >= z:
largest = x
elif y >= x and y >= z:
largest = y
else:
largest = z
# Find the middle number
middle = (x + y + z) - smallest - largest
print("The numbers in ascending order are:", smallest, middle, largest)
```
In this program, we first prompt the user to enter three integers, `x`, `y`, and `z`. We then use conditional statements to find the smallest, largest, and middle numbers among the three.
We compare each number with the other two using `if` and `elif` statements. If a number is smaller than or equal to both of the other two, it is the smallest. If a number is larger than or equal to both of the other two, it is the largest.
Once we have found the smallest and largest numbers, we can calculate the middle number by subtracting them from the sum of all three numbers.
Finally, we print out the three numbers in ascending order to the user.