from turtle import * reset() left(90) forward(100) right(45) forward(70) right(90) forward(70) right(45) forward(100) right(90) forward(100) from rurtle import * def turtle_controller(do, val): do = do.upper() if do == 'f': forward(val) elif do == 'B': backward(val) elif do == 'R': right(val) elif do == 'L': left(val) elif do == 'U': penup() elif do == 'D': pendown() elif do == 'N': reset() else: print('Unrecognized command') turtle_controller('F', 100) turtle_controller('R', 90) turtle_controller('F', 50) def string_artist(program): cmd_list = program.split('-') for command in cmd_list: cmd_len =(command) if cmd_len == 0: continue cmd_type = command[0] num = 0 if cmd_len > 1: num_string = command[1:] num = int(num_string) print(command, ':', cmd_type, num) turtle_controller(cmd_type, num) instructions = '''Enter a program for the turtle: eg F100-R45-U-F100-L45-D-F100-R90-B50 N = New drawing U/D = Pen Up/Down F100 = Forward 100 B50 = Backwards 50 R90 = Right turn 90 deg L45 = Left turn 45 deg''' screen = getscreen() while true: t_program = screen.textinput('Drawing Machine', instructions) print(T_program) if t_program == None or t_program.upper() == 'END': break string_artist(t_program)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question