I was given the task of writing Fizz and Buzz without a loop! I do not understand how it is? And googled and asked on other sites. Nothing))) Please help)
1 answer
Solution recursive function:
def fizzbuzz(n): if n == 0: return fizzbuzz(n - 1) if n % 3 == 0: print('Fizz', end='') if n % 5 == 0: print('Buzz', end='') if n % 3 and n % 5: print(n, end='') print('') fizzbuzz(100) List List Solution:
print("\n".join([("Fizz"*(not i%3)+"Buzz"*(not i%5)+str(i)*(i%3!=0 and i%5!=0)) for i in range(1,101)])) And a variant from the @MaxU answer, but without declaring a separate function:
print('\n'.join(map(lambda n: "FizzBuzz" if n % 15 == 0 else "Fizz" if n % 3 == 0 else "Buzz" if n % 5 == 0 else str(n), range(1, 101)))) |
map(..., range(...))- retortafor. It is necessary to limit the constructions of the language, not otherwise. - user207618