Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print a butterfly pattern using python. #12151

Open
CyberHat92 opened this issue Oct 19, 2024 · 7 comments
Open

Print a butterfly pattern using python. #12151

CyberHat92 opened this issue Oct 19, 2024 · 7 comments
Labels
enhancement This PR modified some existing files

Comments

@CyberHat92
Copy link

Feature description

You need to take a user input n. and print a butterfly pattern using the input received from the user as side length.

star

You need to print the above shown pattern from the image.

@CyberHat92 CyberHat92 added the enhancement This PR modified some existing files label Oct 19, 2024
@CyberHat92
Copy link
Author

Assign me this and use label hacktoberfest.

@Dream-World-Coder
Copy link

is this issue solved? if not then assign it to me, I would like work on it.

@AnaghDeshpande
Copy link

Hey, I have optimized the code and reduced the number of lines of code. Can you assign it to me?

@HeheAnanya
Copy link

Hi please assign this issue to me, if it's not closed

@Mrudul1234
Copy link

Feature description

You need to take a user input n. and print a butterfly pattern using the input received from the user as side length.

star

You need to print the above shown pattern from the image.

@27371123
Copy link

27371123 commented Dec 3, 2024

Size of the butterfly pattern

size = 5

Upper part of the butterfly

for i in range(1, size + 1):
for j in range(1, i + 1):
print("", end="")
for k in range(1, (2 * (size - i)) + 1):
print(" ", end="")
for l in range(1, i + 1):
print("
", end="")
print()

Lower part of the butterfly

for i in range(size - 1, 0, -1):
for j in range(1, i + 1):
print("", end="")
for k in range(1, (2 * (size - i)) + 1):
print(" ", end="")
for l in range(1, i + 1):
print("
", end="")
print()

@niralinayak
Copy link

def butterfly_pattern(n):
# Upper part of the butterfly
for i in range(1, n + 1):
# Print stars on the left side
print("" * i, end="")
# Print spaces in the middle
print(" " * (2 * (n - i)), end="")
# Print stars on the right side
print("
" * i)

# Lower part of the butterfly
for i in range(n, 0, -1):
    # Print stars on the left side
    print("*" * i, end="")
    # Print spaces in the middle
    print(" " * (2 * (n - i)), end="")
    # Print stars on the right side
    print("*" * i)

Change the value of n for a larger or smaller pattern

n = 5
butterfly_pattern(n)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@Mrudul1234 @AnaghDeshpande @niralinayak @Dream-World-Coder @HeheAnanya @CyberHat92 @27371123 and others