Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I count no.of strings executed

for fizzbuzz in range(1,500):
if (fizzbuzz % 3==0 and fizzbuzz % 5==0:
  print(fizzbuzz)
else:
  print(not divisible)

Now, how to see how many fizzbuzz’s are there with exact count.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You simply need to update a counter. Adding to the code you’ve shown and properly indenting:

c = 0

for fizzbuzz in range(1,500):
  if (fizzbuzz % 3==0 and fizzbuzz % 5==0:
    print(fizzbuzz)
    c += 1
  else:
    print(not divisible)

print(c)

Of course, you could also just increment your range by 15, and start with 15:

c = 0

for i in range(15, 500, 15):
  print(fizzbuzz)
  c += 1

print(c)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading