Advertisement
Guest User

fizzbuzz

a guest
Jan 18th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from urllib2 import urlopen, Request
  2. from bs4 import BeautifulSoup
  3. from time import sleep
  4.  
  5.  
  6. def is_multiple_of_x(n, x):
  7.     req = Request('http://www.google.com/search?q={}+%25+{}'.format(n, x))
  8.     req.add_header('User-agent', 'Mozilla/5.0')
  9.     soup = BeautifulSoup(urlopen(req))
  10.     element = soup.find('div', {'id': 'topstuff'}).find('span', {'class': 'nobr'}).text
  11.     res = int(element.split('=')[-1].strip())
  12.     return not res
  13.  
  14.  
  15. def fizzbuzz():
  16.     for i in range(1, 101):
  17.         if is_multiple_of_x(i, 3):
  18.             if is_multiple_of_x(i, 5):
  19.                 print 'fizzbuzz'
  20.             else:
  21.                 print 'fizz'
  22.         elif is_multiple_of_x(i, 5):
  23.             print 'buzz'
  24.  
  25.         else:
  26.             print i
  27.     sleep(3)
  28.  
  29.  
  30. fizzbuzz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement