~1 min read • Updated Oct 1, 2025
Program Overview
This Python program receives three numbers from the user and sorts them in ascending order.
The key constraint: it does not use any conditional statements (if) or loops (for, while).
Instead, it relies on built-in functions and data structures.
Python Code:
# Read three numbers from user
x = float(input("Enter first number: "))
y = float(input("Enter second number: "))
z = float(input("Enter third number: "))
# Sort using built-in sorted() function
sorted_list = sorted([x, y, z])
# Display result
print("\n--- Sorted Numbers ---")
print(sorted_list)
Sample Output:
Enter first number: 9
Enter second number: 3
Enter third number: 7
--- Sorted Numbers ---
[3.0, 7.0, 9.0]
Step-by-Step Explanation:
- The program receives three floating-point numbers from the user
- It places them into a list and uses sorted() to sort the list
- No if statements or loops are used
- The result is printed as a list in ascending order
Written & researched by Dr. Shahin Siami