Ad

Took a small trade-off in increasing the number of iterations by starting at 0 instead of 1, but increased the readability by not having to subtract 1 to reference the correct index.

Code
Diff
  • list = list(range(17))
    
    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 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
    • list = list(range(17))
    • for i in list :
    • if i % 15 == 0 :
    • list[i-1] = 'Fizz Buzz'
    • list[i] = 'Fizz Buzz'
    • elif i % 3 == 0 :
    • list[i-1] = 'Fizz'
    • list[i] = 'Fizz'
    • elif i % 5 ==0 :
    • list[i-1] = 'Buzz'
    • print(list[i-1])
    • list[i] = 'Buzz'
    • list = list[1::]
    • for i in list:
    • print(i)
  • Changed the tuple to a list
  • Now modifies the list values for the purpose of being able to run a test against the final values
Code
Diff
  • list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
    
    for i in list :
        if i % 15 == 0 :
            list[i-1] = 'Fizz Buzz'
        elif i % 3 == 0 :
            list[i-1] = 'Fizz'
        elif i % 5 ==0 :
            list[i-1] = 'Buzz'
            
        print(list[i-1])
    • list = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
    • list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
    • for i in list :
    • if i % 15 == 0 :
    • print('Fizz Buzz')
    • list[i-1] = 'Fizz Buzz'
    • elif i % 3 == 0 :
    • print('Fizz')
    • list[i-1] = 'Fizz'
    • elif i % 5 ==0 :
    • print('Buzz')
    • else :
    • print(i)
    • list[i-1] = 'Buzz'
    • print(list[i-1])