Uploaded by Deyjzhanae Collier

TurtleLab2GuideSheet

advertisement
Turtle Lab #2
General Directions
In this lab you will work, once again with Turtle graphics. Your program will utilize text boxes, print
statement, loops and decision structures. Your delieverables for this assignment will include your Python file
Step 1: Setting up the Screen and the Turtle
1.
2.
3.
4.
Open VS Code and navigate to your new folder. Open your new file.
Import the turtle library.
Establish a color for your turtle and the background screen.
Ask the user, using an input box, what shape they want their turtle object to be. The choices are: classic,
arrow, turtle, circle, square and triangle.
5. Add turtle.exitonclick() at the end of your file so you can watch your code execute without the window
disappearing.
6. Draw a circle somewhere on the screen. You can choose the color and the size and where your circle will
go.
7. Make sure that once you draw your circle, you change the color of your turtle back to where it started.
Step 2: Adding Movement to Your Program
1. Move your turtle object to an area away from the shape you just drew.
2. Create a loop that will allow your turtle object to move around the screen. Use the demo from class to
help. Allow your user 10 moves. The goal is to move the turtle object to somewhere within the circle you
just drew.
Step 3: Did the User Win?
In order to determine if the user’s turtle is within the circle, we need to find out where the turtle is and
compare it against where the circle is. To do that we need to understand how circles are drawn with turtle.
The following code will draw a circle with the turtle.
turtle.circle(100)
The number in the parenthesis, dictates how big the circle will be and more specifically refers to the
radius. In the example above ‘100’ means the circle will have a diameter of 100 and a radius of 50 pixels. The
turtle then draws circle 50 pixels up, 50 pixels down, 50 pixels to the right and 50 pixels to the left. This means
that if we locate the turtle at x = 100 and y = -200, the circle will roughly take up the space between 50 and
1150 on the x axis and -150 and -250 on the y axis.
Now that we know roughly were the circle will be, we need to determine where the turtle ends up after
the user makes their 10 moves. Luckily the turtle has two methods to help us out: xpos and ypos. Therefore
to find out the x coordinate of the turtle we could use the following code:
xpos = turtle.xcor()
To find out where the turtle is on the y axis we can use:
ypos = turtle.ycor()
The last part of this program entails displaying a message on the screen that will tell the user if they
won or not. The turtle has a method for that as well, the write method. The code listed below will print the
message “Sorry you Lost”, align the text in the center of where directed the turtle and will print it in Arial font,
size 16 and bold.
turtle.write("Sorry You Lost", align="center", font=('Arial', '16', 'bold'))
Now that we know how to determine where the circle is located, how to determine where the turtle is
located and how to write a message to the screen, we can finish this program.
Step 4: Finishing up
1. Write the code to determine where the turtle is on the screen.
2. Determine if the location of the turtle is in the circle. If the turtle is in the circle display the message “You
Win!”. Otherwise print “Sorry You Lost”.
Extra Credit ~ 5 points
Add code that will use random numbers for x and y, to determine the starting point of the turtle and
where the circle will be drawn.
Grading
Consult the rubric below to make sure you did not forget anything. Upload your python file to the Turtle
Lab #2 assignment on Canvas.
Exemplary
pts
Competent
pts
Developing
pts
Did not complete
3
Comments in the code
2
Only one comment in
code
2
Declared the necessary
variables.
2
Missing one variable.
1
Missing 2 variables.
0
Missing more than 2
variables or no variable
declarations.
4
Established a color for the
turtle and a background
color. Drew a circle.
3
Missing one element.
2
Missing 2 elements.
0
Missing more than 2
elements or did not
complete.
3
Utilized an input boxes to
ask the user for the shape of
the turtle and the direction
the turtle traveled.
2
Missing one input box.
2
Did not use input boxes
and instead used the
terminal to obtain data
from the user.
0
8
Utilized a loop with a multialternative decision
structure to move the turtle
around the screen.
6
A minor error with the
code.
5
Two minor errors with
the code.
0
7
Determined where the turtle
was on the screen and
utilized an IF structure to
determine if the user won.
6
A minor error with the
code.
4
Two minor errors with
the code.
0
3
A print statement appeared
on the Turtle screen showing
if the user won.
2
A minor error with the
code.
2
Two minor errors with
the code or print
statement appeared in
terminal window.
0
30
TOTAL POINTS
2
Comments are sparse
0
No comments
Too many errors or did
not complete.
Did not use a multialternative IF
structure, too many
errors or did not
complete.
Too many errors or did
not complete.
Too many errors or did
not complete.
Download