Programming Examples
Create a Python program that finds the second smallest number in a list of positive integers (including zero).
Create a Python program that finds the second smallest number in a list of positive integers (including zero).
If input is 5 4 3 2 1, then output should be 2.
If input is 0 0 0 0 1, then output should be 1.
If input is 1 11, then output should be 11.
Solutionnums = list(map(int, input("Enter numbers separated by space: ").split()))
# Remove duplicates and sort
unique_nums = sorted(set(nums))
# Get the second smallest number
if len(unique_nums) >= 2:
print("Second smallest number:", unique_nums[1])
else:
print("Not enough unique numbers to find the second smallest.")
▶ RUN Output/ Explanation: Input: 5 4 3 2 1
Output: Second smallest number: 2
Input: 0 0 0 0 1
Output: Second smallest number: 1