Skip to content

Instantly share code, notes, and snippets.

@Xaypanya
Created December 30, 2022 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xaypanya/791c1c5f987b126683d900c3fe7c199f to your computer and use it in GitHub Desktop.
Save Xaypanya/791c1c5f987b126683d900c3fe7c199f to your computer and use it in GitHub Desktop.
heart pattern in python
n = 8
m = n+1
for i in range(n//2-1):
for j in range(m):
if i == n//2-2 and (j == 0 or j == m-1):
print("*", end=" ")
elif j <= m//2 and ((i+j == n//2-3 and j <= m//4) \
or (j-i == m//2-n//2+3 and j > m//4)):
print("*", end=" ")
elif j > m//2 and ((i+j == n//2-3+m//2 and j < 3*m//4) \
or (j-i == m//2-n//2+3+m//2 and j >= 3*m//4)):
print("*", end=" ")
else:
print(" ", end=" ")
print()
for i in range(n//2-1, n):
for j in range(m):
if (i-j == n//2-1) or (i+j == n-1+m//2):
print('*', end=" ")
elif i == n//2-1:
if j == m//2:
print('F', end=" ")
else:
print(' ', end=" ")
else:
print(' ', end=" ")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment