Advertisement
ivandrofly

Fizz Bizz - Python

Mar 19th, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #!/usr/bin/python
  2. print('=================> <Fizz Buzz> <=================')
  3. def fizzBuzz(myList):
  4.     # 3 = Fizz | # 5 = Buzz
  5.     mystring = ''
  6.     for x in myList:
  7.         if x % 3 == 0:
  8.             mystring = 'Fizz'
  9.         if x % 5 == 0:
  10.             mystring += '-buzz'
  11.                    
  12.         if len(mystring.strip()) > 0:
  13.             print('Num: {0} is {1}'.format(x, mystring))
  14.         else:
  15.             print('Neither', x)
  16.  
  17. print('Enter max list range: ')
  18. maxRange = input()
  19. try:
  20.     x = int(maxRange)
  21.     fizzBuzz(range(1, x))
  22. except:
  23.     print('Something bad happened')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement