why this piece of code is not working as it suppose to do ?!
for i in range (1,101):
if i%3 ==0:
if i%5 ==0:
if i%3==0 or i%5==0:
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
The first thing I see is the identation for the third block (when the number is divisible by 3 and 5). You want to check if it is div by 3 (print fizz), by 5 (print buzz), or by 3 and 5 (fizzbuzz), so the 3 if should be at the same lvl. Then you use i%3==0 OR i%5==0, you should be using and, not or. You want to make sure that both are true
And to add on, you should check for (3 && 5) first and then 3 individually and 5 individually.
or else you'll print somtehing like fizz, buzz, fizzbuzz all on the same line.
Not the answer you are looking for? Search for more explanations.
or you could just remove the check for both entirely, since as it stands now it will print "Fizz" followed by "Buzz" to give "FizzBuzz" for numbers divisible by 15 (although you might want to print a newline afterwards)