In [5]:
spins = input("How many times did you spin? (Enter a negative number for couter-clockwise spins) ")
degrees = ((float(spins) * 360) % 360)
print("You are facing", degrees, "degrees relative to north")
In [1]:
import turtle
wn = turtle.Screen() # creates a graphics window
alex = turtle.Turtle() # create a turtle named alex
alex.speed(1)
alex.shape('turtle')
for i in [0,1,2,3,4,5]:
alex.forward(150) # tell alex to move forward by 150 units
alex.left(85) # turn by 90 degrees
alex.forward(75)
## This won't run as expected with the notebook. Wait a moment for the window to be created.
wn.exitonclick()
The documentation for the module inside of Python can be found here: https://docs.python.org/3.6/library/turtle.html
In [ ]:
# Copied from the documentation example. This is bad practice to do import * DO NOT DO IT!
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
In [14]:
for i in [6, 5, 4, 3]:
print("I have", i, "cookies. I'm going to eat one.")
print('I ate all my cookies')
In [1]:
import turtle
wn = turtle.Screen()
wn.bgcolor("lightgreen")
tess = turtle.Turtle()
tess.color("blue")
tess.shape("turtle")
jim = turtle.Turtle()
jim.color("green")
jim.shape("turtle")
carl = turtle.Turtle()
carl.color("red")
carl.shape("turtle")
tess.up()
carl.up()
jim.up()
# Keep in mind for today's studio
for size in range(5, 60, 2): # start with size = 5 and grow by 2
tess.stamp() # leave an impression on the canvas
carl.stamp()
jim.stamp()
carl.forward(size + 10)
jim.forward(size)
tess.forward(size) # move tess along
carl.right(90)
jim.left(24)
tess.right(24) # and turn her
wn.exitonclick()
In [4]:
from math import sqrt
print(type
(sqrt(4)))
In [6]:
import random
random.seed(5)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
random.seed(15)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
random.seed(22)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
# Setting the seed back to 5 you can observe that it will always have the same results
random.seed(5)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
In [9]:
number_of_beers = 99
for number in range(number_of_beers, 0, -1):
print(number, "bottles of beer on the walll", number,"bottles of beer on the wall take one down pass it around")
print(number - 1, "bottles of beer on the wall")
In [1]:
import turtle
import random
wn = turtle.Screen()
anaise = turtle.Turtle()
hour = 1
lines = 1
angle = 1
anaise.speed(0)
# Set the color mode so the mac is happy.
wn.colormode(255)
#change starting point of line randomly
while lines < 200:
anaise.goto(random.randrange(50), random.randrange(50))
anaise.down()
angle = (random.randrange(360))
anaise.color(random.randrange(255),random.randrange(255),random.randrange(255))
anaise.pensize(random.randrange(11))
anaise.right(angle)
anaise.forward(random.randrange(100))
anaise.up()
#Count the number of times the loop occurs
lines = lines + 1
wn.exitonclick()
In [1]:
import turtle
wn = turtle.Screen()
alex = turtle.Turtle()
sides_number = int(input("How many sides?"))
sides_length = int(input("How long are the sides?"))
line_color = input("What color for the lines?")
fill_color = input("What color for the fill?")
alex.color(line_color)
alex.fillcolor(fill_color)
alex.speed(1)
alex.begin_fill()
for i in range(sides_number):
alex.forward(sides_length)
alex.left((360)/(sides_number))
alex.end_fill()
Show them a random Donut of the day: "Yellow Jacket - creme, sugar, and honey with a glazed top and cake body"
Ask the patron how much they want to pay per donut? Ask the number of donuts they want to buy? (fractional donuts) Take into account the tax rate: 5%
>>> "Here's the donut of the day"
>>> "Yellow Jacket - creme, sugar, and honey with a glazed top and cake body"
>>> "How many donuts?"
>>> "What do you want to pay per donut?"
>>> "Computing price...."
>>> "You shall pay: $price$"
In [ ]:
>>>