-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzz.py
53 lines (38 loc) · 1.11 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
46
47
48
49
50
51
52
53
'''
Write a program that prints the numbers from 1 to 100.
But for multiples of three print "Fizz" instead of the
number and for the multiples of five print "Buzz". For
numbers which are multiples of both three and five
print "FizzBuzz".
Sample output:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz
'''
def fizzbuzz(n: int):
ret = ''
if n % 3 == 0:
ret += 'Fizz'
if n % 5 == 0:
ret += 'Buzz'
if n % 3 != 0 and n % 5 != 0:
ret = str(n)
return ret
def fizzbuzz_without_if_rayan(n: int):
return (n % 3 == 0) * 'Fizz' + (n % 5 == 0) * 'Buzz' + (n % 3 != 0 and n % 5 != 0) * str(n)
def fizzbuzz_without_if_nathan(n: int):
''' Implementação do algoritimo sem uso de if's que ganhou a caneca '''
ret = ''
while (n % 3 == 0):
ret += 'Fizz'
break
while (n % 5 == 0):
ret += 'Buzz'
break
while (n % 3 != 0 and n % 5 != 0):
ret = str(n)
break
return ret
def main():
numbers = [fizzbuzz(n) for n in range(1, 101)]
print(*numbers, sep='\n')
if __name__ == '__main__':
main()