Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class FizzBuzz:
  2. def __init__(self, start, stop):
  3. self.start = start
  4. self.stop = stop + 1
  5.  
  6. def value_for(self, value):
  7. output = ""
  8.  
  9. if value % 3 == 0:
  10. output += "Fizz"
  11. if value % 5 == 0:
  12. output += "Buzz"
  13.  
  14. if len(output) == 0:
  15. output = str(value)
  16.  
  17. return output
  18.  
  19. def fizz(self):
  20. results = []
  21.  
  22. for candidate in range(self.start, self.stop):
  23. results.append(self.value_for(candidate))
  24.  
  25. return results
  26.  
  27. fizzer = FizzBuzz(1, 100)
  28.  
  29. for result in fizzer.fizz():
  30. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement