定義一個函數,參數為三角形的邊長和顏色,並調用該函數繪制兩個邊長顏色不同的等邊三角形
1 def draw(l,color): 2 import turtle 3 turtle.setup(900,600,200,200) 4 turtle.penup() # 筆抬起 5 turtle.fd(-60) 6 turtle.pendown() # 筆放下 7 turtle.pensize(6) 8 turtle.pencolor(color) 9 turtle.seth(60) 10 turtle.fd(l) 11 turtle.seth(-60) 12 turtle.fd(l) 13 turtle.seth(-180) 14 turtle.fd(l) 15 16 l,l_ = eval(input("輸入兩個三角形的邊逗號隔開:")) 17 color= input("輸入第一個三角形顏色:") 18 color_ = input("輸入第二個三角形顏色:") 19 20 draw(l,color) 21 import turtle 22 turtle.penup() 23 turtle.fd(300) 24 turtle.pendown() 25 draw(l_,color_) 26 turtle.done()