1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Is passing the same value to a function twice bad practice?

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    this program prints a pyramid (its from a cs50 problem set). I call the function recursively by decrementing n, but i also wanted to keep track of its initial value in all the loops after the first one, so I made the function take two arguments, both of which are the same value(height) is this bad?

    def main():
    height = get_h()
    pyram(height, height)


    def pyram(n, k):
    if n > 1:
    pyram(n-1, k)
    print(" " * (k - n), end = "")
    print("#" * n, end = " ")
    print("#" * n)


    def get_h():
    while True:
    try:
    inp = int(input("height?: "))
    except ValueError:
    print("no")
    if inp > 0:
    return inp


    if __name__ == "__main__":
    main()

    Continue reading...

Compartilhe esta Página