Python - Number analysis program

Asked

Viewed 48 times

-3

Come on! I’m trying to do a program exercise, where the user will give the amount of numbers he wants to be checked, what are the numbers, and if he wants the highest or lowest, number between them. PROBLEM: I’m not getting the input given in the chooseUser read for a program decision-making;

print ('------------------------------------------------------------')
print ('               PROGRAMA Avaliação numero                    ')
print ('------------------------------------------------------------')

quantidade_num = input ('Quantos serão os números a serem avaliados? ')
lista_numero = []

i = 1
while i <= int (quantidade_num):
    numero_input = input ('Número #' + str(i) + ' ')
    lista_numero.append(numero_input)
    i += 1

escolhaUser = input('Quer o menor ou o maior número? ')

if escolhaUser == 'maior':
    escolhaUser = True
else:
    escolhaUser = False

def maior(colecao):
    maior_item = colecao[0]
    for item in lista_numero:
        if item > maior_item:
            maior_item = item
    return maior_item

def menor(colecao):
    menor_item = colecao[0]
    for item in lista_numero:
        if item < menor_item:
            menor_item = item
    return menor_item

if escolhaUser == True:
    decisao = maior(lista_numero)
else:
    decisao = menor(lista_numero)

print (str(decisao(lista_numero)))

Typeerror: 'str' Object is no callable

  • The question is formatted with markdown.

  • Where is print(str(decisao(lista_numero))) swap for print(decisao)

  • Another thing python has to native functions min() and max() which render their functions unnecessary maior() and menor().

1 answer

2

Just change the 'last line of code' that your problem will be solved.

change

print(str(decisao(lista_numero))) 

for:

print(decisao)

Ready!

It’s a simple syntax problem. You didn’t create the method decisao to call you through the way decisao(). You just created the option decisao and has indicated through the if in your program what will be the user’s decision whether to be the "largest" or "smallest"

Browser other questions tagged

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