A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

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'

  • This Question is Open
  1. osanseviero
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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

  2. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    And to add on, you should check for (3 && 5) first and then 3 individually and 5 individually.

  3. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    or else you'll print somtehing like fizz, buzz, fizzbuzz all on the same line.

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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)

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.