running mswlogo for python 1

前几天,一个朋友找我要mswlogo安装包,没找到,我自己做了一个。

import turtle as t
t.title('mswlogo')

def run(sth):
    b=sth.split(' ')
    exec('t.'+b[0]+'('+b[1]+')')

def repeat(sth):
    a=sth.split('[',1)
    b = a[0].split(' ')
    c = a[1].split(']')
    d=c[0].split(' ')
    print(int(b[1]))    
    if not len(d)%2 == 0:
        return
    e=len(d)/2
    f=0
    for nnn in range(int(b[1])):
        for i in range(int(e)):
            print(d[f])
            print(d[f+1])
            n_run(d[f]+' '+d[f+1])
            f=f+2
        f=0

def n_run(a):
    while True:
        a=a.lower()
        if a.split(' ')[0] == 'repeat':
            repeat(a)
        else:
            run(a)

while True:
    a=input('mswlogo run >>> ')
    a=a.lower()
    if a.split(' ')[0] == 'repeat':
        repeat(a)
    else:
        run(a)

这只是第一版以后会更新

你可能感兴趣的:(python,开发语言)