In: Computer Science
<Python Coding>
Book : Discovering Computer Science chap3.2 (open source)
1. Write a modified version of the flower bloom program that draws a flower with 18 sides, using an angle of 100.
2. Write a program that uses a for loop to draw a square with side length 200.
3. Write a program that uses a for loop to draw a rectangle with side length 200 and width 100.
Write a program that uses a for loop to draw a rectangle with side length 200 and width 100.
Screenshot
Program
from turtle import Turtle,Screen
my_turle = Turtle()
#Loop to create a rectangle
for i in range(2):
#Length
my_turle.forward(200)
#Turn
my_turle.left(90)
#Width
my_turle.forward(100)
my_turle.left(90)
#To lock screen
screen = Screen()
screen.exitonclick()
------------------------------------------------------------------------------------
Write a program that uses a for loop to draw a square with side length 200
Screenshot
Program
#Using loop to draw square in Python Turtle
from turtle import Turtle,Screen
my_turtle = Turtle()
#Loop to create a square
for i in range(4):
#Side
my_turtle.forward(200)
#Turn
my_turtle.left(90)
#To lock screen
screen = Screen()
screen.exitonclick()
------------------------------------------------------------------------
Write a modified version of the flower bloom program that draws a flower with 18 sides, using an angle of 100.
Screenshot
Program
from turtle import Turtle, Screen
#Create turtle object
my_turtle = Turtle()
#Draw flower using for loop
for i in range(18):
#Set start position
head = my_turtle.heading()
#Set radius and extend
my_turtle.circle(100, 60)
#generate each petal left side
my_turtle.left(120)
my_turtle.circle(100, 60)
my_turtle.setheading(head)
my_turtle.left(360 /18)
#To show full flower in the screen without close the screen
screen = Screen()
screen.exitonclick()
------------------------------------------------------------------
Note:-
I assume you are expecting this way of drawing