Part of the series

Several example codes

~2 min read • Updated Oct 13, 2025

Program Overview

This Python program reads a 2D matrix and checks whether at least one predefined curiosity element is present.
If found, it prints "Yes"; otherwise, it prints "No".


Python Code:


def read_matrix(rows: int, cols: int) -> list[list[str]]:
    print(f"Enter elements for a {rows}×{cols} matrix:")
    matrix = []
    for i in range(rows):
        row = input(f"Row {i+1}: ").strip().split()
        if len(row) != cols:
            print("Each row must contain exactly the number of columns.")
            exit()
        matrix.append(row)
    return matrix

def curiosity_check(matrix: list[list[str]], curiosity: set[str]) -> str:
    for row in matrix:
        for item in row:
            if item in curiosity:
                return "Yes"
    return "No"

# Define curiosity elements
curious_elements = {"?", "!", "🤔", "wonder", "strange"}

# Read matrix dimensions
r = int(input("Number of rows: "))
c = int(input("Number of columns: "))

# Read and process
mat = read_matrix(r, c)
result = curiosity_check(mat, curious_elements)
print(f"\nQuery response: {result}")

Sample Output:


Input matrix:  
hello yes no  
wonder maybe no  
no no no  

Output:  
Query response: Yes

Written & researched by Dr. Shahin Siami