DEV Community

Codes With Pankaj
Codes With Pankaj

Posted on

Create a butterfly star pattern :

# Python butterfly star pattern
# Code by @codeswithpankaj.com

def create_butterfly_pattern(rows):
    """
    Function to create a butterfly star pattern.

    :param rows: Number of rows in each wing of the butterfly.
    """
    for i in range(0, rows):
        # Print left wing spaces
        for j in range(0, i):
            print(" ", end="")

        # Print left wing stars
        for k in range(0, 2 * (rows - i) - 1):
            print("*", end="")

        # Move to the next line after each row
        print()

    for i in range(rows-2, -1, -1):
        # Print right wing spaces
        for j in range(0, i):
            print(" ", end="")

        # Print right wing stars
        for k in range(0, 2 * (rows - i) - 1):
            print("*", end="")

        # Move to the next line after each row
        print()

# Example: Create a butterfly pattern with 5 rows in each wing
create_butterfly_pattern(5)
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay