why doesn't this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why doesn't this code work?

it says break is not part of the loop words = ["Python", "fun"] index = 0 words.insert(index, "is") if words == ["is","Python","fun"]: print('hi') elif words == ["is","is","Python","fun"]: break print(finished)

19th Jul 2016, 12:28 PM
Aaron Briggs
8 Answers
+ 1
break can only be used in a loop finished should be in quotes
19th Jul 2016, 12:38 PM
Gershon Fosu
Gershon Fosu - avatar
+ 1
Yup Yup
19th Jul 2016, 12:41 PM
Gershon Fosu
Gershon Fosu - avatar
+ 1
the problem with the break is that it is used to get out of the loop (while,for). since if is not a loop python interpreter gets confused and asks you what do you want with your break there.
19th Jul 2016, 12:44 PM
RedAnt
RedAnt - avatar
0
Im not sure about the break, but it looks like there arent any quotation marks around the word finished.
19th Jul 2016, 12:35 PM
codinator999
0
so break wouldn't be needed?
19th Jul 2016, 12:40 PM
Aaron Briggs
0
thanks
19th Jul 2016, 12:43 PM
Aaron Briggs
0
Try change the break command to pass and add quotationmarks to finished. Then it should work! :-)
19th Jul 2016, 12:58 PM
Mathias Karlsson
Mathias Karlsson - avatar
0
break вне цикла. а где у тебя вообще цикл?
19th Jul 2016, 5:09 PM
Misha Hack
Misha Hack - avatar