Problem when trying to create another call? Call related to how many times a value appears in the list

夙愿已清 提交于 2020-04-17 19:06:21

问题


Here is the code:

from typing import Any

list = list(range(1, 41))
print(list)
listValues = []
for i in range(1, 5):  # 1,2,3,4
    value = int(input("Digite o valor:" + str(i) + ":"))  # Digite o valor
    listValues.append(value)
print(value)

for value in listValues:
        print(value)
        if value in list:
            print("Valor " + str(value) + " encontrado.")
        else:
            print("Valor " + str(value) + " não encontrado.")
value = int(input("Digite o valor, para achar a posição:" +str(i) + ":"))
pos = listValues.append(value)
for i in range(len(list)):
 if list[i] == value: pos = i
print(pos)
cont = list.count(value)
value = int(input("O valor" +str(i) + "aparece" + cont(value)))

As the last part of the code:

cont = list.count(value)
value = int(input("O valor" +str(i) + "aparece" + cont(value))) 

doesn't recognize the action I want to play:

/usr/local/bin/python3.8 /Users/gss/Desktop/script/lista.py
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
Digite o valor:1:30
Digite o valor:2:20
Digite o valor:3:40
Digite o valor:4:50
50
30
Valor 30 encontrado.
20
Valor 20 encontrado.
40
Valor 40 encontrado.
50
Valor 50 não encontrado.
Digite o valor, para achar a posição:4:50
None
Traceback (most recent call last):
  File "/Users/gss/Desktop/script/lista.py", line 23, in <module>
    value = input("O valor" +str(i) + "aparece" + cont(value))
TypeError: 'int' object is not callable

Process finished with exit code 1

回答1:


I don't know exactly what your are doing, I'm gonna get that out of the way first. Next I recommend not using python keywords for variable names, it seems to work as far as i saw but just a recommendation.

File "/Users/gss/Desktop/script/lista.py", line 23, in value = input("O valor" +str(i) + "aparece" + cont(value)) TypeError: 'int' object is not callable

This error is because you tried to use 'cont' variable as if it was a function.

You defined: cont = list.count(value)

cont would be an int, that why you get the type error.



来源:https://stackoverflow.com/questions/61257203/problem-when-trying-to-create-another-call-call-related-to-how-many-times-a-val

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!