Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib2 import urlopen, Request
- from bs4 import BeautifulSoup
- from time import sleep
- def is_multiple_of_x(n, x):
- req = Request('http://www.google.com/search?q={}+%25+{}'.format(n, x))
- req.add_header('User-agent', 'Mozilla/5.0')
- soup = BeautifulSoup(urlopen(req))
- element = soup.find('div', {'id': 'topstuff'}).find('span', {'class': 'nobr'}).text
- res = int(element.split('=')[-1].strip())
- return not res
- def fizzbuzz():
- for i in range(1, 101):
- if is_multiple_of_x(i, 3):
- if is_multiple_of_x(i, 5):
- print 'fizzbuzz'
- else:
- print 'fizz'
- elif is_multiple_of_x(i, 5):
- print 'buzz'
- else:
- print i
- sleep(3)
- fizzbuzz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement