-
Notifications
You must be signed in to change notification settings - Fork 372
/
0-fizzbuzz.py
executable file
·39 lines (32 loc) · 975 Bytes
/
0-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
#!/usr/bin/python3
""" FizzBuzz
"""
import sys
def fizzbuzz(n):
"""
FizzBuzz function prints numbers from 1 to n separated by a space.
- For multiples of three print "Fizz" instead of the number and for
multiples of five print "Buzz".
- For numbers which are multiples of both three and five print "FizzBuzz".
"""
if n < 1:
return
tmp_result = []
for i in range(1, n + 1):
if (i % 3) == 0:
tmp_result.append("Fizz")
elif (i % 3) == 0 and (i % 5) == 0:
tmp_result.append("FizzBuzz")
elif (i % 5) == 0:
tmp_result.append("Buzz")
else:
tmp_result.append(str(i))
print(" ".join(tmp_result))
if __name__ == '__main__':
if len(sys.argv) <= 1:
print("Missing number")
print("Usage: ./0-fizzbuzz.py <number>")
print("Example: ./0-fizzbuzz.py 89")
sys.exit(1)
number = int(sys.argv[1])
fizzbuzz(number)