Files
openHPI/fizzbuzz.py
T
2024-10-11 15:32:15 +02:00

58 lines
1.4 KiB
Python

import numpy as np
print("No german translation.")
class Solution:
def fizzbuzz(self, n):
result = []
for i in range(1,n+1):
if i%3 == 0:
if i%5 == 0:
result.append("FizzBuzz")
else:
result.append("Fizz")
elif i%5 == 0:
result.append("Buzz")
else:
result.append(str(i))
return result
def fizzbuzz2(self, n, div1, div2):
result = []
for i in range (1, n+1):
if i%div1 == 0 and i%div2 == 0:
result.append("FizzBuzz")
elif i%div1 == 0:
result.append("Fizz")
elif i%div2 == 0:
result.append("Buzz")
else:
result.append(str(i))
return result
obj = Solution()
div1 = 2
div2 = 10
print(obj.fizzbuzz(30))
print(obj.fizzbuzz2(30, div1, div2))
"""
class Solution(object):
def fizzBuzz(self, n):
:type n: int
:rtype: List[str]
result = []
for i in range(1,n+1):
if i% 3== 0 and i%5==0:
result.append("FizzBuzz")
elif i %3==0:
result.append("Fizz")
elif i% 5 == 0:
result.append("Buzz")
else:
result.append(str(i))
return result
ob1 = Solution()
print(ob1.fizzBuzz(30))
"""