1
I have the following rule:
Create a function that receives a list of integers, and replaces the items as below:
- if Multiples of 3 = 'Fizz'
- multiples of 5 = 'Buzz'
- multiples of 3 and 5 = 'Fizzbuzz'
I created the program below:
intList = list()
intList = [1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]
newlist=list()
def fizzbuzz( lista ):
for item in lista:
if item % 3 == 0 and item % 5 == 0:
lista.remove(item)
newlist.append(item) ='fizzbuzz'
elif item % 3 == 0:
lista.remove(item)
newlist.append(item) ='fizz'
elif item % 5 == 0:
lista.remove(item)
newlist.append(item)='buzz'
else:
newlist.append(item)=item
fizzbuzz(newlist)
But returns the following error:
C: Python27 my_scripts>for_loop.py File "C: Python27 my_scripts for_loop.py", line 15 newlist.append(item)='buzz' Syntaxerror: can’t assign to Function call
Any idea what I can do? At the end of the precise program displays the list of integers and strings.
Thanks!
Thank you so much TNT! It worked, thanks!
– LeoGallerDev
Plz, if possible mark as answered and give a note up. Thank you!
– TNT
I tried TNT, but only one answer can be marked as correct, note up tb is not available to me pq it is necessary level 15 of reputation to be able to mark it.
– LeoGallerDev