-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz.py
More file actions
24 lines (20 loc) · 744 Bytes
/
Copy pathfizzbuzz.py
File metadata and controls
24 lines (20 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''
Take in a list of integers and replaces all integers that
are evenly divisible by 3 with the string "fizz", replaces all integers divisible by 5 with the string "buzz",
and replaces all integers divisible by both 3 and 5 with the string "fizzbuzz".
https://realpython.com/lessons/range-vs-enumerate/#description
'''
from random import randint
def fizz_buzz(numbers: list):
for k,v in enumerate(numbers):
if (v % 3 == 0) and (v % 5 == 0):
numbers[k] = "fizzbuzz"
elif v % 3 == 0:
numbers[k] = "fizz"
elif v % 5 == 0:
numbers[k] = "buzz"
return numbers
numbers = [ randint(x, 20) for x in range(10)]
cop = numbers.copy()
res = fizz_buzz(numbers)
print(*zip(cop, res))