Ad
  • use of a generator
Code
Diff
  • def fizzBuzz(num):
        for i in range(1,num):
            yield ("Fizz Buzz" if i % 3 == 0 and i % 5 == 0 else ("Fizz" if i % 3 == 0 else ("Buzz" if i % 5 == 0 else i)))
    
    list = list(fizzBuzz(17))
    
    • list = list(range(17))
    • def fizzBuzz(num):
    • for i in range(1,num):
    • yield ("Fizz Buzz" if i % 3 == 0 and i % 5 == 0 else ("Fizz" if i % 3 == 0 else ("Buzz" if i % 5 == 0 else i)))
    • for i in list :
    • if i % 15 == 0 :
    • list[i] = 'Fizz Buzz'
    • elif i % 3 == 0 :
    • list[i] = 'Fizz'
    • elif i % 5 ==0 :
    • list[i] = 'Buzz'
    • list = list[1::]
    • for i in list:
    • print(i)
    • list = list(fizzBuzz(17))