Python Coding Challenge

The following are my solutions to the "Fizzbuzz"python Coding Challenge.
The intent was to define a function as it pertains to the coursework covered in “Preparing for the Technical Interview”.

The first function follows the instructions step-by-step
This includes the general syntax expected. I also intended to provide very readable code for the benefit of anyone who may need it.

The second function solution is refactored and more advanced.

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

This second function outputs line by line by line not a list.

print(*map(lambda i: 'Fizz'*(not i%3)+'Buzz'*(not i%5) or i, range(1,101)),sep='\n')
1 Like

I like the use of the lambda function. Nice work.

Equivalent to saying, 'function function'. A lambda is an anonymous immediately executing function that acts upon an iterable.

Bottom line, it’s a lambda or it’s a function. They are quite differently purpose based.