-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhackerJob_challenge_FizzBuzz.py
85 lines (60 loc) · 1.78 KB
/
hackerJob_challenge_FizzBuzz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import unittest
import sys
class Solution:
def run(self, N, M):
#
# Some work here; return type and arguments should be according to the problem's requirements
#
new_list = []
for i in range(N, M + 1):
new_list.append(i)
sequence = []
for x in new_list:
if (x % 3 == 0) and (x % 5 == 0):
sequence.append('FizzBuzz')
else:
if x % 3 == 0:
sequence.append('Fizz')
elif x % 5 == 0:
sequence.append('Buzz')
else:
sequence.append(str(x))
print(*(sequence), sep=", ")
return ','.join(sequence)
so = Solution()
# n =int(input())
# m=int(input())
so.run(1, 5)
class SolutionMethods(unittest.TestCase):
##
# /!\ Unit Tests are optional but highly recommended /!\
##
# First Example
##
# def test_example(self):
# self.assertEqual("this is an example", "this is an example")
##
# Second Example
##
def test_run(self):
solution = Solution()
self.assertEqual(solution.run(1, 5), "1,2,Fizz,4,Buzz")
def test_run2(self):
solution = Solution()
self.assertEqual(solution.run(10, 15), "Buzz,11,Fizz,13,14,FizzBuzz")
if __name__ == "__main__":
unittest.main()
"""Requirement
Write a program that returns the numbers from N to M both inclusive. But for multiples of three give "Fizz" instead of the number and for the multiples of five give "Buzz". For numbers which are multiples of both three and five, give "FizzBuzz".
INPUT
int N
Int M
OUTPUT
string sequence
^^ the resulting sequence using commas as separators between elements
EXAMPLE
Input
1,5
Output
"1,2,Fizz,4,Buzz"
"""