0% found this document useful (0 votes)
112 views5 pages

Codehs

The document contains code for several turtle graphics programs. The first program draws increasingly larger squares to make a pattern. The second program asks the user to guess a secret number between 1-10 and provides feedback if their guess is too high or low. The third program is similar but draws different shapes to indicate if the guess is too high or too low. The last program draws rows of circles of decreasing length based on user input.

Uploaded by

berikerden08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views5 pages

Codehs

The document contains code for several turtle graphics programs. The first program draws increasingly larger squares to make a pattern. The second program asks the user to guess a secret number between 1-10 and provides feedback if their guess is too high or low. The third program is similar but draws different shapes to indicate if the guess is too high or too low. The last program draws rows of circles of decreasing length based on user input.

Uploaded by

berikerden08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

2.18.

length = 50

speed(0)

def drawSquare(l):

for i in range(4):

forward(l)

left(90)

while length < 400:

penup()

backward(length/2)

right(90)

forward(length/2)

left(90)

pendown()

drawSquare(length)

penup()

forward(length/2)

left(90)

forward(length/2)

right(90)

length = length + 50
2.18.5

speed(10)

secret_number = 4

def checkmark():

color("green")

right(45)

forward(30)

left(90)

forward(50)

user_number = int (input("Guess a number through 1-10:"))

while secret_number != user_number:

user_number = int(input("Sorry, but try again:"))

pensize(10)

checkmark()

2.19.4

speed(10)

secret_number = 4

def checkmark():

color("green")

penup()

backward(30)

pendown()
right(45)

forward(30)

left(90)

forward(60)

def higher():

pendown()

left(90)

forward(100)

right(45)

backward(30)

forward(30)

left(90)

backward(30)

forward(30)

right(45)

right(90)

def lower():

pendown()

left(90)

backward(100)

right(45)

forward(30)

backward(30)

left(90)
forward(30)

backward(30)

right(135)

user_number = int (input("Guess a number through 1-10:"))

while secret_number != user_number:

if user_number > secret_number:

lower()

elif user_number < secret_number:

higher()

else:

checkmark()

clear()

penup()

setposition(0,0)

user_number = int(input("Guess again(1-10)"))

2.19.5

speed(0)

penup()

row_value=0

radius = 25
def move_to_row(num_blocks):

x_value = -((num_blocks*50)/2) + radius

y_value = -200+(50*row_value)

setposition(x_value,y_value)

def draw_block_row(num_blocks):

for i in range(num_blocks):

pendown()

circle(radius)

penup()

forward(50)

num_blocks=int(input("How Many Blocks On The Bottom Row? (8 or less): "))

for i in range(num_blocks):

move_to_row(num_blocks)

row_value=row_value+1

draw_block_row(num_blocks)

num_blocks=num_blocks-1

You might also like