FizzBuzz
This famous exercise helps you practice conditions and the order of checks. Write a function fizzbuzz that takes a number n and returns a string by these rules: if the number is divisible by 15, return FizzBuzz; if it is divisible only by 3, return Fizz; if it is divisible only by 5, return Buzz. If none of the rules match, return the number itself as a string.
Примеры
Ввод
1Вывод
"1"Ввод
3Вывод
"Fizz"Ввод
15Вывод
"FizzBuzz"Нужно реализовать
def fizzbuzz(n: int) -> str:
Теги
stringsmath
Log ind for at se indsendelseshistorik
Log indLog ind for at bruge AI-mentor
Log indVisible tests
1
Input
1Expected
"1"2
Input
3Expected
"Fizz"3
Input
5Expected
"Buzz"4
Input
15Expected
"FizzBuzz"5
Input
7Expected
"7"6
Input
30Expected
"FizzBuzz"Focus radio
Paused · SomaFM · Fluid