# Python Challenge - FizzBuzz, FizzBuzz

def multipleOfThree(number):
if number % 3 == 0:
return True
else:
return False

def multipleOfFive(number):
if number % 5 == 0:
return True
else:
return False

def fizzbuzz(limit):
fizzbuzz_list =
for i in range(1, limit + 1):
if multipleOfThree(i) and multipleOfFive(i):
fizzbuzz_list.append(“FizzBuzz”)
elif multipleOfThree(i):
fizzbuzz_list.append(“Fizz”)
elif multipleOfFive(i):
fizzbuzz_list.append(“Buzz”)
else:
fizzbuzz_list.append(i)
return fizzbuzz_list

print(fizzbuzz(16))

My first attempt at this challenge

def fizzbuzz(limit): # Write your code here list = [] for i in range(1, limit+1): if i % 3 == 0 and i % 5 == 0: list.append("FizzBuzz") elif i % 3 == 0: list.append("Fizz") elif i % 5 == 0: list.append("Buzz") else: list.append(i) return list print(fizzbuzz(16))

easy solution to implement:
def fizzbuzz(limit):
result =
for num in range(1, limit + 1):
if num % 3 == 0 and num % 5 == 0:
result += [“FizzBuzz”]
continue
elif num % 3 == 0:
result += [“Fizz”]
continue
elif num % 5 == 0:
result += [“Buzz”]
continue
result += [num]
return result

print(fizzbuzz(16))

def fizzbuzz(limit): lst = list(range(1, limit + 1)) for j in range(len(lst)): if lst[j] % 3 == 0 and lst[j] % 5 != 0: lst[j] = "Fizz" elif lst[j] % 5 == 0 and lst[j] % 3 != 0: lst[j] = "Buzz" elif lst[j] % 5 == 0 and lst[j] % 3 == 0: lst[j] = "FizzBuzz" return lst print(fizzbuzz(16))
def fizzbuzz(limit): # Write your code here lst = [] for num in range(1, limit+1): if num % 15 == 0: lst.append('FizzBuzz') elif num % 3 == 0: lst.append('Fizz') elif num % 5 == 0: lst.append('Buzz') else: lst.append(num) return lst print(fizzbuzz(16))

Line 5 could leverage the LCM rather than using logic:

``````if n % 15 == 0:
``````

Your right!, it can be shorter

1 Like