Cannot find the IndentationError: unexpected indent error?
Cannot find the IndentationError: unexpected indent error?
#Modify the code below so that the function sense, which
#takes p and Z as inputs, will output the NON-normalized
#probability distribution, q, after multiplying the entries
#in p by pHit or pMiss according to the color in the
#corresponding cell in world.
p=[0.2, 0.2, 0.2, 0.2, 0.2]
world=['green', 'red', 'red', 'green', 'green']
Z = 'red'
pHit = 0.6
pMiss = 0.2
def sense(p, Z):
q=[]
for i in range(p):
if(Z==word[i]):
q.append(p[i]*pMiss)
else:
q.append(p[i]*pHit)
return q
print sense(p,Z)
def sense(p, Z):
不应缩进。
我认为您的函数签名缩进不正确,请查看以下代码:
p=[0.2, 0.2, 0.2, 0.2, 0.2]
world=['green', 'red', 'red', 'green', 'green']
Z = 'red'
pHit = 0.6
pMiss = 0.2
def sense(p, Z):
q=[]
for i in range(p):
if(Z==word[i]):
q.append(p[i]*pMiss)
else:
q.append(p[i]*pHit)
return q
print sense(p,Z)
Note: A code block (body of a function, loop etc.) starts with indentation and ends with the first unindented line. The amount of indentation is up to you, but it must be consistent throughout that block.
#Modify the code below so that the function sense, which #takes p and Z as inputs, will output the NON-normalized #probability distribution, q, after multiplying the entries #in p by pHit or pMiss according to the color in the #corresponding cell in world.
p=[0.2, 0.2, 0.2, 0.2, 0.2]
world=['green', 'red', 'red', 'green', 'green']
Z = 'red'
pHit = 0.6
pMiss = 0.2
def sense(p, Z):
q=[]
for i in range(p):
if(Z==word[i]):
q.append(p[i]*pMiss)
else:
q.append(p[i]*pHit)
return q
print sense(p,Z)
def sense(p, Z):
不应缩进。
我认为您的函数签名缩进不正确,请查看以下代码:
p=[0.2, 0.2, 0.2, 0.2, 0.2]
world=['green', 'red', 'red', 'green', 'green']
Z = 'red'
pHit = 0.6
pMiss = 0.2
def sense(p, Z):
q=[]
for i in range(p):
if(Z==word[i]):
q.append(p[i]*pMiss)
else:
q.append(p[i]*pHit)
return q
print sense(p,Z)
Note: A code block (body of a function, loop etc.) starts with indentation and ends with the first unindented line. The amount of indentation is up to you, but it must be consistent throughout that block.