daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Oct 18th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import sys
  3.  
  4. def FizzBuzz(file):
  5.  
  6.     f = open(file, 'r')
  7.     while 1:   
  8.         line = f.readline()#read a line
  9.         if not line:
  10.             break
  11.         game(line)
  12.         pass   
  13.     f.close
  14.    
  15.  
  16. def game(read_data):
  17.     fizz = getNum(read_data)#take a number
  18.     read_data = update(read_data)#remove that number
  19.     buzz = getNum(read_data)#take a number
  20.     read_data = update(read_data)#remove that number
  21.     limit = getNum(read_data)
  22.     play(int(fizz), int(buzz), int(limit))
  23.  
  24.  
  25. def play(Fizz, Buzz, Limit):#this plays the game
  26.     result = ''
  27.     for x in range(Limit):
  28.  
  29.         y=x+1#we add one to the range
  30.         if ((y%Fizz==0)and(y%Buzz==0)):
  31.             result += ' FB'
  32.         elif (y % Fizz) == 0:
  33.             result += ' F'
  34.         elif (y % Buzz) == 0:
  35.             result += ' B'
  36.         else:
  37.             result += ' '+str(y)
  38.     print result[1:]
  39.  
  40. def getNum(data):#returns the first number from a list
  41.     a = ''
  42.     for x in range(len(data)):
  43.         if data[x] != ' ':
  44.             data[x+2:]
  45.             a += data[x]
  46.         else:
  47.             return a
  48.     return a#this should never happen. 
  49.        
  50.  
  51. def update(data):
  52.     for x in range(len(data)):
  53.         if data[x] != ' ':
  54.             return data[x+2:]#returns the list minus the first number
  55.     return data
  56.  
  57. if __name__=="__main__":
  58.  
  59.         FizzBuzz(sys.argv[1])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top