Part of the series

Several example codes

~1 min read • Updated Oct 11, 2025

Program Overview

This Python program receives a sample input and determines whether it represents a "bag".
The logic can be based on string matching, object type, or any custom rule depending on context.
For simplicity, we assume the input is a string and check whether it matches the word "bag".


Python Code:


def is_bag(sample: str) -> bool:
    return sample.strip().lower() == "bag"

# Run the program
sample_input = input("Enter the sample: ")

if is_bag(sample_input):
    print("The sample is a bag.")
else:
    print("The sample is not a bag.")

Sample Output (input: "Bag"):


The sample is a bag.

Step-by-Step Explanation:

- The user enters a sample string
- The is_bag function trims whitespace and converts the input to lowercase
- It checks if the result equals "bag"
- The program prints whether the sample is a bag or not


Written & researched by Dr. Shahin Siami