尝试创建另一个电话时遇到问题?与值在列表中出现多少次相关的呼叫 [英] Problem when trying to create another call? Call related to how many times a value appears in the list
问题描述
这是代码:
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
推荐答案
我不知道您在做什么,我首先要解决这个问题.接下来,我建议不要对变量名使用python关键字,就我所知,它似乎可以正常工作,但仅是一项建议.
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.
文件"/Users/gss/Desktop/script/lista.py",第23行,值= input("O valor" + str(i)+"aparece" + cont(value))TypeError:'int '对象不可调用
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
此错误是因为您试图像使用函数一样使用'cont'变量.
This error is because you tried to use 'cont' variable as if it was a function.
您定义: cont = list.count(value)
cont将会是一个int,这就是为什么会出现类型错误.
cont would be an int, that why you get the type error.
这篇关于尝试创建另一个电话时遇到问题?与值在列表中出现多少次相关的呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!