Working through a coding book with my son, "Help Your Kids with Computer Coding" by DK. Great book so far.
For a project we're building a drawing machine, that's supposed to split a string into a series of commands that will be drawn.
But the code skips to the final item in the string without outputting the other items. The book says this command, loops through the list of items in the string:
for cmd in cmd_list:
Is there something missing to make it go through every element of the string? Below is a sample of the code and then the output.
Thanks!
#String Artist
def string_artist(program):
cmd_list = program.split('-')
print(cmd_list) #I added this line to confirm the split#
for cmd in cmd_list:
cmd_len = len(cmd)
if cmd_len == 0:
continue
cmd_type = cmd[0]
num = 0
if cmd_len > 1:
num_string = cmd[1:]
num = int(num_string)
print(cmd, ':', cmd_type, num)
turtle_controller('cmd_type', num)
outputs:
>>> string_artist('N-L90-F100-F101-F102')
['N', 'L90', 'F100', 'F101', 'F102']
F102 : F 102
Unrecognized Command
Any help will be greatly appreciated! Want to keep moving forward with my son's learning this. Thanks!