You will use Turtle graphics to draw a picture in Python 3.4 containing multiple
ID: 662734 • Letter: Y
Question
You will use Turtle graphics to draw a picture in Python 3.4 containing multiple shapes of multiple colors and arranged to be visually pleasing. Although you are free to decide the precise shape(s) and layout for your picture, some aspect of the picture must depend on a numeric value input by the user. For example, the input might determine the size of the shapes, the number of shapes, or their spacing
Your program must:
1. Output a brief descriptive message of what the program does. 2. Repeatedly prompt for the input until the user supplies values of the correct form (discard incorrect inputs). Your prompt should say what form of input is needed. 3. Draw a picture containing multiple shapes of multiple colors, where the input value(s) is (are) used to determine some aspect of the shapes and/or their layout.
In programming your solution, you must:
1. Use at least two repetition (while or for) statements. 2. Use at least one selection (if) statement.
We show example output produced by two different programs that meet these requirements at the end of this write-up. You may be creative and create your own program, or you may choose to mimic one of these two examples. The second example shows error checking being tested.
The first program draws squares of a fixed size; they all start at the origin, but are arranged in a circular manner by manipulating the orientation of the turtle.
The second program draws concentric circles of many colors. The user specifies the number of circles and the radius of the largest circle.
So choose to reproduce one of these two functions. Need to be able to have an input where the user specifies the amount of circles or squares being produced.
Explanation / Answer
1.
import turtle
print("Enter the size of square ")
n = int(raw_input())
window = turtle.Screen()
window.bgcolor("lightgreen")
st = turtle.Turtle()
st.color("blue")
st.pensize(4)
st.forward(n)
st.left(90)
st.forward(n)
st.left(90)
st.forward(n)
st.left(90)
st.forward(n)
2.
import turtle
print("Enter the number of circle to be draw")
n = int(raw_input())
print("Enter the radius of largest circle to be draw")
nn = int(raw_input())
t = 1
def drawCircle(anyTurtle, radius):
circumference = 2 * 3.1415 * radius
sideLength = circumference / 360
drawPolygon(anyTurtle, sideLength, 360)
window = turtle.Screen()
st = turtle.Turtle()
diff = float(nn)/float(n)
while(True):
if (n == 0):
break
drawCircle(wheel, nn)
nn = nn - dif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.