The list of numbers you will be searching is given below. You can copy and paste this list into your code to get started.
numbers = [3, 5, 2, 8, 5, 1, 5, 7, 9, 5, 4, 6, 5, 0, 5]
In order to count, you will need to set up a variable to keep track. You will want to start this variable at 0 since you havenβt found any "5"βs yet. Then, you will need to loop through each number in the list and check if it is equal to 5. If it is, you will want to add 1 to your counting variable. Finally, after you have checked all the numbers in the list, you will want to print out the value of your counting variable.
Solution.
For all of these mini projects, there are many ways to solve the problem. You may use different variable names, a different style with your loops, or other small things. Before changing all your code to match this solution, check first if you got the correct count! If you did, great job! If not, try to debug your code first. If you are still stuck, then you can look at this solution for help.
The correct count is 6. Here is one way to write the code to get that answer:
numbers = [3, 5, 2, 8, 5, 1, 5, 7, 9, 5, 4, 6, 5, 0, 5]
count = 0 #start counting at 0 outside the loop
for number in numbers:
if number == 5: #check if the number is equal to 5
count = count + 1 #if so, add 1 to the count
print(count) #print the final count after the loop
