所以我正在制作一个程序来使用turtle绘制特定的字母,并且我已经设置了一个参数比例来根据输入提示影响程序的大小和笔粗细。这就是我所拥有的...我不断收到错误消息,说未定义比例。
import turtle
def drawLetter( letter ):
if letter == " ":
space(scale)
elif letter == "i":
i_lc(scale)
elif letter == "I":
i_uc(scale)
elif letter == "s":
s_lc(scale)
elif letter == "S":
s_uc(scale)
elif letter == "C":
c_uc(scale)
elif letter == "c":
c_lc(scale)
def space(scale):
turtle.up()
turtle.forward( 30 * scale )
def questionMark():
""" Draw a question mark.
"""
turtle.forward( 10 )
turtle.down()
turtle.left( 90 )
turtle.forward( 2 )
turtle.up()
turtle.forward( 3 )
turtle.down()
turtle.forward( 5 )
turtle.right( 90 )
turtle.forward( 10 )
turtle.left( 90 )
turtle.forward( 10 )
turtle.left( 90 )
turtle.forward( 20 )
turtle.left( 90 )
turtle.forward( 5 )
turtle.up()
turtle.forward( 15 )
turtle.left( 90 )
turtle.forward ( 30 )
def i_uc(scale):
""" Draw an upper case I.
"""
turtle.down()
turtle.forward( 10 )
turtle.left( 90 )
turtle.forward( 20 )
turtle.left( 90 )
turtle.forward( 10 )
turtle.left( 180 )
turtle.forward( 20 )
turtle.left( 180 )
turtle.forward( 10 )
turtle.left( 90 )
turtle.forward( 20 )
turtle.left( 90 )
turtle.forward( 10 )
turtle.up()
turtle.forward( 10 )
def i_lc(scale):
""" Draw a lower case i.
"""
turtle.forward( 10 )
turtle.down()
turtle.left( 90 )
turtle.forward( 11 )
turtle.up()
turtle.forward( 2 )
turtle.down()
turtle.forward( 2 )
turtle.up()
turtle.right( 180 )
turtle.forward( 15 )
turtle.left( 90 )
turtle.forward( 20 )
def s_uc(scale):
""" Draw an upper case S.
"""
turtle.left( 90 )
turtle.forward( 20 )
turtle.right( 90 )
turtle.forward( 20 )
turtle.right( 180 )
turtle.down()
turtle.forward( 20 )
turtle.left( 90 )
turtle.forward( 10 )
turtle.left( 90 )
turtle.forward( 20 )
turtle.right( 90 )
turtle.forward( 10 )
turtle.right( 90 )
turtle.forward( 20 )
turtle.left( 180 )
turtle.up()
turtle.forward( 30 )
def s_lc(scale):
""" Draw a lower case s.
"""
turtle.down()
turtle.forward( 20 * scale )
turtle.left( 90 )
turtle.forward( 5 * scale )
turtle.left( 90 )
turtle.forward( 20 * scale )
turtle.right( 90 )
turtle.forward( 5 * scale )
turtle.right( 90 )
turtle.forward( 20 * scale )
turtle.up()
turtle.right( 90 )
turtle.forward( 10 * scale )
turtle.left( 90 )
turtle.forward( 10 * scale )
def c_uc(scale):
turtle.down()
turtle.forward( 20 * scale )
turtle.forward( -20 * scale )
turtle.left( 90 )
turtle.forward( 20 * scale )
turtle.right( 90 )
turtle.forward( 20 * scale )
turtle.forward( -20 * scale )
turtle.left( 90 )
turtle.forward( -20 * scale )
turtle.up()
turtle.right( 90 )
turtle.forward( 20 * scale )
def c_lc(scale):
turtle.down()
turtle.forward( 20 * scale )
turtle.forward( -20 * scale )
turtle.left( 90 )
turtle.forward( 10 * scale )
turtle.right( 90 )
turtle.forward( 20 * scale )
turtle.forward( -20 * scale )
turtle.left( 90 )
turtle.forward( -10 * scale )
turtle.up()
turtle.right( 90 )
turtle.forward( 20 * scale )
def main():
scale == input("Enter scale:")
turtle.pensize(scale)