After watching this video by Tom Scott, I decided to make a program that follows that idea. This is what I came up with:
# If a number is divisible by the key, add the value
RULES = {
3: "Fizz",
5: "Buzz"
}
def is_divisible(num: int) -> list:
output = []
for divider in RULES:
if (num % divider) == 0:
output.append(RULES[divider])
return output
for num in range(100):
output = is_divisible(num + 1) # Increment num by 1 so it is 1-100 not 0-99
if not output:
print(num + 1)
else:
print("".join(output))
My whole idea behind the way I made this is because I wanted it to be as expandable as possible. That way if you wanted to change the code to do something different (like the examples at the end of the above video), you could just add it. I would like to know if there is anything I could do to improve its changeableness and if there are any glaring problems that when fixed doesn't affect the changeability of the code.
def is_divisible(n: int) -> list: return [RULES[d] for d in RULES if n % d == 0]
:) \$\endgroup\$