Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How would I make a variable that counts?

+5 votes
asked Feb 2, 2023 by YC72909 (340 points)
Hello,

I want to make a variable that counts how many times a number appears in a set. My count variable isn't working though. It always show "0" as the count. Here is a part of my code:

if num1 == 7:
    one_zero + seven_count

Thank you,

YC72909 Scratch & Online GDB

1 Answer

0 votes
answered Feb 3, 2023 by Peter Minarik (86,040 points)

You have to increment a value of your designated counter, e.g. like this:

count = 0
if num1 == 7:
    count = count + 1

Good luck!

commented Feb 3, 2023 by YC72909 (340 points)
Oh,  I see, thank you.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...