Python Forum
Using a If-else statement as solution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a If-else statement as solution
#1
Hope you all are having a good learning experience. Here I have a secondary solution proposal for a Quiz, a bit traditional but should work flawlessly.

However I am unable to catch the mistake in my code to arrive at the same results as to the code given by the course.

Here is the python code, please help me out if you can:

#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):
#
#ADD YOUR CODE HERE
#
q=
for i in range(len§):
#hit = (Z==world)
#q.append(p[i]((hitpHit)+((1-hit)*pMiss)))
print i
if(Z==world[i]):
q.append(p[i]*pHit)
print i,"Hit"
print i
else:
q.append(p[i]*pMiss)
print i,"Miss"
return q

print sense(p,Z)

Response : Here I have used some print statements to debug the code and I see that my code does not want to process index 0 and index 3. If one of you are kind enough to help me it would help me a long way. Thanks in advance.

0
0
1
1 Hit
1
2
2 Hit
2
3
3
4
4
4 Miss
[0.12, 0.12, 0.04000000000000001]
[/i][/i][/i][/i]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020