Function statement within Python FUNCTION

Asked

Viewed 108 times

0

I’m trying to declare a function that shows a line below the result of another function. This line adapts to the size of the returned result in the 'main' function. Follow the code and error message that is showing:

from time import sleep

def mostraLinha(tamLinha):
  print('=' * tamLinha)
  print()

def maior(* n):
  print('PROCESSANDO...', flush=True)
  sleep(1.5)
  for num in n:
    sleep(0.6)
    print(f'{num}', end = ' > ', flush=True)
    if num == n[0]:
      maior = num
    else:
      if num > maior:
        maior = num
  print()
  print(f'Foram analisados {len(n)} números e o maior é o {maior}.')
  parâmetro = len(n)
  mostraLinha(parâmetro)


def mostraLinha():
  print('=' * 25)
  print()


print('Desempacotando PARÂMETROS')
print('-' * 30)
print()
maior(-5, 14, 102, 3, 5)
maior(3, 5)
maior(1056, 100456, 0, -345, 6, 7, 8, 15, 21)

ERROR MESSAGE:

MOSTRALINHA() TAKES 0 POSITIONAL ARGUMENTS BUT 1 WAS GIVEN

1 answer

1


You have two roles with the same name:

def mostraLinha(tamLinha):
  print('=' * tamLinha)
  print()

and:

def mostraLinha():
  print('=' * 25)
  print()

Here you pass a parameter: mostraLinha(parâmetro), as the function runs the second and it seems to me that you want to run the first, I believe that the second should not even exist.

  • Perfect William. I think I sent the wrong message, do you believe? It was not in the code block that second function! Details make the difference hehe

  • @dev.Uri if solved the problem mark the answer as correct, thank you

  • Made friend! Getting the hang of it...

  • @dev.Uri thank you/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.