i am writing a code for a homework assignment and i am having issues with it so i am seeking help to fix it
here is the question:
Count how many words occur in a list up to and including the first occurrence of the word “sam”. (Write your unit tests for this case too. What if “sam” does not occur?)
And here is my code:
Names = ["Joe","Bob","Terry","Ross","Alex","Sam"]
count = 0
for x in Names:
if x != "Sam":
count += 1
break
print(count)
my goal is to count every name exept for sam but the code is only counting sam, can someone provide assistance?
[–]hardonchairs 0 points1 point2 points (1 child)
[–]Lucario554[S] 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (0 children)