From a299a94e3a319d917327ffab242076a2d89787d5 Mon Sep 17 00:00:00 2001 From: Dan <57764947+tigerpa616@users.noreply.github.com> Date: Wed, 26 Oct 2022 13:23:40 -0400 Subject: [PATCH] Add files via upload --- fizzbuzz.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 fizzbuzz.py diff --git a/fizzbuzz.py b/fizzbuzz.py new file mode 100644 index 00000000..8c46ee65 --- /dev/null +++ b/fizzbuzz.py @@ -0,0 +1,14 @@ +#Given an integer n, return a string array answer (1-indexed) where: +#answer[i] == "FizzBuzz" if i is divisible by 3 and 5. +#answer[i] == "Fizz" if i is divisible by 3. +#answer[i] == "Buzz" if i is divisible by 5. +#answer[i] == i (as a string) if none of the above conditions are true. + +def FizzBuzz(self, n): + ls=[] + for i in range(1,n+1): + if i%3==0 and i%5==0:ls.append("FizzBuzz") + elif i%3==0:ls.append("Fizz") + elif i%5==0:ls.append("Buzz") + else:ls.append(str(i)) + return ls \ No newline at end of file