0

So I want to know the position of the number '1' in the arrays, My code detects the first '1' but it does not detect the one's after.

NumberOfPlayers=2
P1SCOREARRAY=[1,3,1,3,4,5,6]
P2SCOREARRAY=[1,6,1,3,4,1,6]
#Hole
HOLEINONE=1
if NumberOfPlayers==2:
  index = P1SCOREARRAY.index(HOLEINONE)
  if index==0:
    index=0+1
  print("scored a hole in one in round--> ",index,)

  index = P2SCOREARRAY.index(HOLEINONE)
  if index==0:
    index=0+1
  print("scored a hole in one in round--> ",index,)

The output I get -->

scored a hole in one in round-->  1
scored a hole in one in round-->  1

The output I want -->

scored a hole in one in round-->  1,3
scored a hole in one in round-->  1,3,6
  • [How to find all occurrences of an element in a list](https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list) – Mechanic Pig Jul 27 '22 at 16:07
  • @MechanicPig Don't just post the link, use Flag to report it as a duplicate. – Barmar Jul 27 '22 at 16:10
  • @Barmar I've flagged it before, but I withdrew it because I used a wrong link, so I can't flag it again. – Mechanic Pig Jul 27 '22 at 16:12

0 Answers0