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.
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
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])
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(actual, expected, [optional] message) # test.assert_not_equals(actual, expected, [optional] message) # You can use Test.describe and Test.it to write BDD style test groupings test.assert_equals( list, [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'Fizz Buzz', 16] )
- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(actual, expected, [optional] message)
- # test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings- # You can use Test.describe and Test.it to write BDD style test groupings
- test.assert_equals(
- list,
- [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'Fizz Buzz', 16]
- )