-
Notifications
You must be signed in to change notification settings - Fork 0
/
FizzBuzz.py
executable file
·45 lines (39 loc) · 1.04 KB
/
FizzBuzz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import sys
MAX=21
def printWithNewlines():
for i in range(1, MAX):
modthree = i % 3
modfive = i % 5
if modthree == 0 and modfive == 0:
print 'FizzBuzz'
elif modthree == 0:
print 'Fizz'
elif modfive == 0:
print 'Buzz'
else:
print i
def printWithoutNewlinesWithSpaces():
for i in range(1, MAX):
modthree = i % 3
modfive = i % 5
if modthree == 0:
print 'Fizz',
if modfive == 0:
print 'Buzz',
if modthree != 0 and modfive != 0:
print i,
def printWithoutNewlinesWithoutSpaces():
for i in range(1, MAX):
modthree = i % 3
modfive = i % 5
if modthree == 0:
sys.stdout.write('Fizz')
if modfive == 0:
sys.stdout.write('Buzz')
if modthree != 0 and modfive != 0:
sys.stdout.write(str(i))
print
# printWithNewlines()
# printWithoutNewlinesWithSpaces()
printWithoutNewlinesWithoutSpaces()