moving the worm move the worm by adding segment in the direction it is moving if direction =up newhead {' 'wormcoords[head][' ']' 'wormcoords[head][' ' elif direction =down newhead {' 'wormcoords[head][' ']' 'wormcoords[head][' ' elif direction =left newhead {' 'wormcoords[head][' ' ' 'wormcoords[head][' '] elif direction =right newhead {' 'wormcoords[head][' ' ' 'wormcoords[head][' '] wormcoords insert( newheadto move the wormwe add new body segment to the beginning of the wormcoords list because the body segment is being added to the beginning of the listit will become the new head the coordinates of the new head will be right next to the old head' coordinates whether is added or subtracted from either the or coordinate depends on the direction the worm was going this new head segment is added to wormcoords with the insert(list method on line the insert(list method unlike the append(list method that can only add items to the end of listthe insert(list method can add items anywhere inside the list the first parameter for insert(is the index where the item should go (all the items originally at this index and after have their indexes increase by oneif the argument passed for the first parameter is larger than the length of the listthe item is simply added to the end of the list (just like what append(doesthe second parameter for insert(is the item value to be added type the following into the interactive shell to see how insert(worksspam ['cat''dog''bat'spam insert( 'frog'spam ['frog''cat''dog''bat'spam insert( spam ['frog''cat''dog''bat' spam insert( 'horse'spam ['frog''cat''horse''dog''bat' email questions to the authoral@inventwithpython com