Part of the series

Several example codes

~1 min read • Updated Oct 13, 2025

Program Overview

This Python program reads a 4-element array and checks whether its elements are sorted in ascending order.
If they are, it prints "Yes"; otherwise, it prints "No".


Python Code:


def is_sorted_ascending(arr: list[int]) -> str:
    return "Yes" if arr == sorted(arr) else "No"

# Read input from user
raw_input = input("Enter 4 numbers separated by space: ")
numbers = list(map(int, raw_input.strip().split()))

if len(numbers) != 4:
    print("You must enter exactly 4 numbers.")
else:
    result = is_sorted_ascending(numbers)
    print(f"\nCheck result: {result}")

Sample Output:


Input: 3 5 7 9  
Output: Check result: Yes

Input: 3 7 5 9  
Output: Check result: No

Written & researched by Dr. Shahin Siami