Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anurag1101/h-shaped_pattern

A simple Python script that generates a customizable H-shaped pattern based on user input. The thickness of the pattern can be adjusted, making it a great exercise for beginners to learn about string manipulation, loops, and formatting in Python.
https://github.com/anurag1101/h-shaped_pattern

iteration loops pattern python python-script python3

Last synced: about 9 hours ago
JSON representation

A simple Python script that generates a customizable H-shaped pattern based on user input. The thickness of the pattern can be adjusted, making it a great exercise for beginners to learn about string manipulation, loops, and formatting in Python.

Awesome Lists containing this project

README

        

**H-Shaped Pattern**

**Description**:

This project generates a customizable H-shaped pattern using Python, where the size and thickness of the "H" can be controlled by user input. The pattern is constructed using the character 'H', and the script displays a symmetric "H" shape with vertical and horizontal bars that adjust based on the input value.

**Overview**:

This project is a Python script that dynamically generates an H-shaped pattern using a customizable thickness value provided by the user. The H is constructed using the letter 'H' and is visually symmetric, with vertical bars on the sides and a horizontal bar in the middle. The program is ideal for beginners to learn how to manipulate strings, use loops, and format output for creating visual patterns in Python.

This project demonstrates basic string operations, looping techniques, and the power of Python’s built-in methods like rjust(), ljust(), and center(). By altering the thickness, users can see how the size of the pattern changes, making it a good exercise for both learning and experimenting with code output.

**Motivation**:

The motivation behind this project was to build a simple yet effective Python program that shows how text-based patterns can be created and manipulated based on user input.

This script offers a fun, hands-on way for learners to experiment with basic control structures and string formatting in Python.

It also serves as a great example for:

Beginners who want to improve their understanding of loops and string manipulation.

Anyone looking to explore how ASCII art and similar patterns can be created programmatically.

**Features**:

Generates a visual H-shaped pattern based on user-defined thickness.

Easy to modify and understand for beginners and learners.

Shows Python's use of for loops, string formatting, and basic logic for pattern creation.

**How It Works**:

The user is prompted to enter the thickness (height) of the "H".

The program prints the top vertical bars, the middle horizontal bar, and the bottom vertical bars symmetrically, depending on the thickness.

**Character and Layout**:

The letter 'H' is used as the character to create the pattern. The overall pattern consists of:

Two vertical bars (on the left and right).

One horizontal bar that runs through the middle.

Depending on the thickness provided by the user, the number of rows and columns increases, resulting in a larger or smaller "H".

**Key Components of the Pattern**:

**Top Half (Vertical Bars):** The first part of the H is created by printing the left and right vertical bars of the H.

**Middle Section (Horizontal Bar):** The middle part is a horizontal bar that connects both vertical sides.

**Lower Half (Mirrored Vertical Bars):** The bottom half is a mirror image of the top half, which gives the H its symmetrical appearance.

**Key Python Methods Used**:

**rjust():** Right-justifies the text by padding spaces on the left.

**ljust():** Left-justifies the text by padding spaces on the right.

**center():** Centers the text by padding spaces on both sides.

**Getting Started**:

**Prerequisites**:

Python 3.x should be installed on your system.

**How to Run the Code**:

Clone or download the repository.

Open a terminal or command prompt.

Navigate to the folder where the script is located.

**Run the script using Python**: python h_shaped_pattern.py

Input the desired thickness when prompted.

**License**:

This project is licensed under the MIT License.