fizzbuzz python best solution code example
Example 1: fizzbuzz python
def minInput():
Min = 1
return(Min)
def maxInput():
Max=100
return(Max)
def creator(i):
item = ""
if task(i,3,"fizz")=="fizz":
item = item+task(i,3,"fizz")
if task(i,5,"buzz")=="buzz":
item = item+task(i,5,"buzz")
if task(i,7,"pezz")=="pezz":
item = item+task(i,7,"pezz")
if item == "":
item = i
return item
def task(i,d,word):
if i%d==0:
return (word)
def main():
Max = maxInput()
Min = minInput()
for i in range(Min,Max):
print(creator(i))
main()
Example 2: python fizzbuzz solution
def prime(n):
if n > 1:
for i in range(2, n):
if (n % i) == 0:
break
else:
print(n, "prime number")
for num in range(1, 100):
result = ""
if prime(num):
result += "Prime"
else:
if num % 3 == 0 and num % 5 == 0:
result += "FizzBuzz"
print(num, result)
elif num % 3 == 0:
result += "Fizz"
print(num, result)
elif num % 5 == 0:
result += "Buzz"
print(num, result)
else:
print(num)
if __name__ == '__main__':
print('All done')
Example 3: fizzbuzz in python
def fizzBuzz(size):
for i in range(size - (size -1), size + 1):
localResult = "fizz" if not i % 3 else ""
localResult = localResult + "buzz" if not i % 5 else localResult
localResult = str(i) if localResult == "" else localResult
print(localResult)