+ 1
What's wrong with this code??
3 ответов
+ 2
from __future__ import annotations
# 👆🏻👆🏻
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
# ans list
ans = []
for num in range(1,n+1):
divisible_by_3 = (num % 3 == 0)
divisible_by_5 = (num % 5 == 0)
if divisible_by_3 and divisible_by_5:
# Divides by both 3 and 5, add FizzBuzz
ans.append("FizzBuzz")
elif divisible_by_3:
# Divides by 3, add Fizz
ans.append("Fizz")
elif divisible_by_5:
# Divides by 5, add Buzz
ans.append("Buzz")
else:
# Not divisible by 3 or 5, add the number
ans.append(str(num))
return ans
# 👇🏻👇🏻
fb=Solution().fizzBuzz(25)
for w in fb:
print(w)
+ 2
n = int(input())
for x in range(1, n, 2):
if x % 3 == 0 and x % 5 == 0:
print("SoloLearn")
elif x % 3 == 0:
print("Solo")
elif x % 5 == 0:
print("Learn")
else:
print(x)
+ 1
Forgot to import annotations from future
Thanks to Prakash Kumar