[Python] Solid Heart Printing

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    I want to print a solid heart which i'm able to but the issue i'm facing is that I'm not able to print it for smaller values.

    def print_heart(n):
    for y in range(n//2,-n,-1): # Vertical axis
    row = ""
    for x in range(-n, n + 1): # Horizontal axis
    formula = (x * 0.05) ** 2 + (y * 0.1) ** 2 - 1
    if formula ** 3 - (x * 0.05) ** 2 * (y * 0.1) ** 3 <= 0:
    row += "*"
    else:
    row += " "
    print(row)

    if __name__ == "__main__":
    n = int(input("Enter size of heart (e.g., 10 for small, 20 for large): "))
    print_heart(n)


    I'm doing something wrong with the y-axis, as for n =24 i'm getting the perfect heart whereas for n<23 a incomplete heart is printing.

    [​IMG][​IMG]

    Continue reading...

Compartilhe esta Página