Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python';int';对象不可调用_Python_Int_Typeerror_Callable - Fatal编程技术网

python';int';对象不可调用

python';int';对象不可调用,python,int,typeerror,callable,Python,Int,Typeerror,Callable,我得到了python错误“TypeError:'int'对象不可调用”,我理解这意味着我不小心将括号直接放在变量或类似的东西之后,但我在代码中没有看到这一点。我的代码是 numFather = random.randrange(0, 10) numMother = random.randrange = 10 - numFather print numFather print numMother child = [] childgen = [] for FatherCounter in range

我得到了python错误“TypeError:'int'对象不可调用”,我理解这意味着我不小心将括号直接放在变量或类似的东西之后,但我在代码中没有看到这一点。我的代码是

numFather = random.randrange(0, 10)
numMother = random.randrange = 10 - numFather
print numFather
print numMother
child = []
childgen = []
for FatherCounter in range(0, numFather):
    child.append(FatherTraits[random.randrange(0,5)])
for MotherCounter in range(0, numMother):
    child.append(MotherTraits[random.randrange(0,5)])
错误在

child.append(FatherTraits[random.randrange(0,5)])
如果我把这一点说出来的话,这种情况还会再次发生

child.append(MotherTraits[random.randrange(0,5)])
有人知道发生了什么吗?

你放在哪里了

numMother = random.randrange = 10 - numFather

您已将编号
10-numFather
分配给
random.randrange
。因此,
random.randrange
现在是一个数字,而不是一个函数。无论您试图做什么,都不是这样。

我同意@khelwood,random.randrange被设置为整数值,但这里没有其他编辑

父亲特质和母亲特质还没有定义。代码行
child.append(FatherTraits[random.randrange(0,5)])
正在调用FatherTraits的随机数并将其附加到child

因此,通过定义
FatherTraits
MotherTraits
,您的代码应该可以工作

import random

numFather = random.randrange(0, 10)
numMother = 10 - numFather

child = []
childgen = []

FatherTraits = ['a','b','c','e','f','g']
MotherTraits = ['u','v','w','x','y','z']


for FatherCounter in range(0, numFather):
    child.append(FatherTraits[random.randrange(0,5)])
for MotherCounter in range(0, numMother):
    child.append(MotherTraits[random.randrange(0,5)])

你认为这有什么作用-
random.randrange=10-numbather
numMother=random.randrange=10-numbather
这一行将random.randrange设置为
int
。你想在这里做什么?我猜他想要
numMother=random.randrange(0,10numbather)
或者干脆
numMother=10-numbather
。就是这样。愚蠢的错误:我把错误的东西放在那行,当我回去修理它时,我不小心留下了一些原来的行