Fizzbuzz

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

# you can write to stderr for debugging purposes, e.g.
# sys.stderr.write(“this is a debug message\n”)

def solution(N):
for x in range(1000):
if x % 3 == 0 and x % 5 == 0 and x % 7 == 0:
print(“FizzBuzzWoof”);
continue
elif x % 3 == 0 and x % 5 == 0:
print(“FizzBuzz”);
elif x % 3 == 0 and x % 7 == 0:
print(“FizzBuzz”);
elif x % 5 == 0 and x % 7 == 0:
print(“FizzWoof”);
elif x % 3 == 0:
print(“Fizz”);
elif FizzBuzz % 5 == 0:
print(“Buzz”);
else x % 5 == 0:
print(“Woof”);
print(x)

error

 

Example test:   24
Output (stderr):

Traceback (most recent call last):
File “exec.py”, line 102, in <module>
main()
File “exec.py”, line 61, in main
sol = __import__(‘solution’)
File “/tmp/solution.py”, line 9
elif x % 3 == 0 and x % 5 == 0:
^
SyntaxError: invalid syntax

RUNTIME ERROR (tested program terminated unexpectedly)

 

in progress 0
Python 6 months 2 Answer 2032 views 0

About purity

Answers ( 2 )

  1. rg123

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel

    This is a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

    for fizzbuzz in range(50):
        if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:
            print("fizzbuzz")
            continue
        elif fizzbuzz % 3 == 0:
            print("fizz")
            continue
        elif fizzbuzz % 5 == 0:
            print("buzz")
            continue
        print(fizzbuzz)
    

    More: http://www.w3resource.com/python-exercises/python-conditional-exercise-10.php

  2. Please briefly explain why you feel this answer should be reported .

    Report
    Cancel

    You really don’t need all those comparisons, try building the output progressively!
    Add your “Woof” to this piece of code! =)

    for fizzBuzzer in range(1, 51):
    	verse = ""
    	if (fizzBuzzer % 3 == 0):
    		verse += "Fizz"
    	if (fizzBuzzer % 5 == 0):
    		verse += "Buzz"
    	if (verse == ""):
    		print(fizzBuzzer)
    		continue
    	print (verse)
    

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>