anonymous
  • anonymous
why this piece of code is not working as it suppose to do ?! #FizzBuzz for i in range (1,101): if i%3 ==0: print 'Fizz' if i%5 ==0: print 'Buzz' if i%3==0 or i%5==0: print 'FizzBuzz'
MIT 6.00 Intro Computer Science (OCW)
jamiebookeater
  • jamiebookeater
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

osanseviero
  • osanseviero
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
Curry
  • Curry
And to add on, you should check for (3 && 5) first and then 3 individually and 5 individually.
Curry
  • Curry
or else you'll print somtehing like fizz, buzz, fizzbuzz all on the same line.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
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)

Looking for something else?

Not the answer you are looking for? Search for more explanations.