Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 6 - Functions - Programming Exercises - Page 212: 6.40

Answer

code

Work Step by Step

# 6.40 (Turtle: filled rectangle and circle) Write the following functions that fill a rectangle # with the specified color, center, width, and height, and a circle with the specified # color, center, and radius. # # Fill a rectangle # def drawRectangle(color = "black", # x = 0, y = 0, width = 30, height = 30): # # Fill a circle # def drawCircle(color = "black", x = 0, y = 0, radius = 50): # Fill a rectangle import turtle def drawRectangle(color="black", x=0, y=0, width=30, height=30): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.begin_fill() turtle.color(color) for i in range(4): turtle.forward(width) turtle.left(90) turtle.forward(height) turtle.end_fill() # Fill a circle def drawCircle(color="black", x=0, y=0, radius=50): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.begin_fill() turtle.color(color) turtle.circle(radius) turtle.end_fill() def main(): drawRectangle("Blue", 60, 60, 100, 200) drawCircle() turtle.done() main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.