1st commit
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
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))
|
||||||
|
"""
|
||||||
Reference in New Issue
Block a user