6.3. Change the color and size
importturtle
tia=turtle.Turtle()
tia.pensize(10)
tia.color("red")
tia.forward(200)
tia.left(90)
tia.color("green")
tia.forward(200)
tia.left(90)
tia.color("yellow")
tia.forward(200)
tia.left(90)
tia.color("blue")
tia.forward(200)
6.4. Draw some different shapes
importturtle
timmy=turtle.Turtle()
timmy.pensize(5)
#Movetofirstposition
timmy.penup()
timmy.goto(10,60)
timmy.pendown()
#Drawapurplerectangle,120by50
timmy.color("purple")
timmy.forward(120)
timmy.left(90)
timmy.forward(50)
timmy.left(90)
timmy.forward(120)
timmy.left(90)
timmy.forward(50)
#Movetonextposition
timmy.penup()
timmy.goto(420,60)
timmy.setheading(0)
timmy.pendown()
#Drawanorangetrianglewithsidesthatare60pxlong
timmy.color("orange")
timmy.forward(60)
timmy.left(120)
timmy.forward(60)
timmy.left(120)
timmy.forward(60)
6.5. Filling shapes with colors
#Createturtle
importturtle
tina=turtle.Turtle()
tina.color("lightGreen")
tina.pensize(8)
#Drawalightgreensquarewithyellowfill
tina.fillcolor("yellow")
tina.begin_fill()
tina.forward(200)
tina.left(90)
tina.forward(200)
tina.left(90)
tina.forward(200)
tina.left(90)
tina.forward(200)
tina.left(90)
tina.end_fill()
7. Introduction to variables
7.1. Calculate donut orders... Mmmm... Donuts....
#Glazeddonutscost$3,filleddonutscost$4andminidonuts
cost$2
#Calculatetotalcostfororder#1:5glazed,3filledand6
minidonuts
order1_cost=5*3+3*4+6*2
#Calculatetotalcostfororder#2:2glazed,1filledand10
minidonuts
order2_cost=2*3+4+10*2
#Displayordersummaries
print("Order#1comesto:${}".format(order1_cost))
print("Order#2comesto:${}".format(order2_cost))
7.2. Use variables to make code more flexible
#Glazeddonutscost$3,filleddonutscost$4andminidonuts
cost$2
glazed_donut=3
filled_donut=4
mini_donut=2
#Calculatetotalcostfororder#1:5glazed,3filledand6
minidonuts
order1_cost=5*glazed_donut+3*filled_donut+6*
mini_donut
#Calculatetotalcostfororder#2:2glazed,1filledand10
minidonuts
order2_cost=2*glazed_donut+1*filled_donut+10*
mini_donut
#Displayordersummaries
print("""Order#1comesto:${}
Order#2comesto:${}""".format(order1_cost,order2_cost))
7.3. Write a program for game purchases using variables
#Setuppricevariables
ps3_game=20
ps4_game=45
discount=10
#Order#1:1PS3gameand2PS4games
order1_price=1*ps3_game+2*ps4_game
#Order#2:4PS3games,3PS4games
order2_price=4*ps3_game+3*ps4_game‐discount
#Printouttotalordercosts
print("Order1costs:${}".format(order1_price))
print("Order2costs:${}".format(order2_price))
7.4. Ask for user input to make the program interactive
#Setuppricevariables
ps3_game=20
ps4_game=45
#Askfornumberofeachgametobepurchased
num_ps3_games=int(input("HowmanyPS3games?:"))
num_ps4_games=int(input("HowmanyPS4games?:"))
#Calculatetotalforeachtypeofgame
ps3_total=num_ps3_games*ps3_game
ps4_total=num_ps4_games*ps4_game
#Calculatetotalcost
total_cost=ps3_total+ps4_total
#Printouttotalordercost
print("Yourordercosts:${}".format(total_cost))
#Optionalordersummary
print("""Ordersummary‐youordered:
{0}PS3gamesfor${1}
{2}PS4gamesfor${3}""".format(num_ps3_games,ps3_total,
num_ps4_games,ps4_total))