NOTE: You will also need to create a .py file in Thonny to do some of this activity, but you WILL NOT need to submit this to Moodle.
Copy and paste your python program into the word doc and state the answer that you got for the sum.
Copy and paste this program into Thonny. Be sure to update the header after you modify the program.
# This program draws polygons with increasing numbers of sides
# to demonstrate how polygons with large numbers of sides approach a circle
#
# Author: D. Palmer
#
# Date: September 8, 2022
import turtle
t=turtle.Turtle()
t.speed('fastest')
# This function draws a polygon with a parameter specified number of sides
def drawPolygon(numSides):
t.setheading(90)
t.penup()
t.goto(-300,0)
t.pendown()
for sides in range(numSides):
t.forward(50)
t.right(360/numSides)
# draws polygons of increasing numbers of sides to demonstrate the trend towards
# a circle
drawPolygon(3)
drawPolygon(4)
drawPolygon(5)
drawPolygon(6)
drawPolygon(7)
drawPolygon(8)
drawPolygon(9)
drawPolygon(10)
drawPolygon(15)
drawPolygon(20)
drawPolygon(30)
Copy and paste this program below into Thonny.
def archimedesOctagon():
side = 2 * math.sin(math.radians(45/2.0))
polygonCircumference = 8 * side
return (polygonCircumference / 2)
Write a function to produce an approximation for pi using a decagon (10-sided polygon). It should be very similar to the octagon version, but the angle should be 36 instead of 45. Compare its approximation to the octagon.
Copy and paste your modified program into the document. Write a short answer (in the document) explaining your findings.
Copy and paste the program below into Thonny:
# This program has a function that calculates Pi using Archimedes approximation
# The function mathematically creates a polygon of a parameterized number of sides
# and then uses that value to algebraically approximate Pi
#
# Author: D. Palmer
#
# Date: Sept. 8, 2022
import math
def archimedesPiApprox(numsides):
circApprox = (numsides * 2 * math.sin(math.radians(360/(2*numsides))))
piApprox = circApprox / 2
return piApprox
print("Pi with 3 sides: ", archimedesPiApprox(3))
print("Pi with 4 sides: ", archimedesPiApprox(4))
print("Pi with 5 sides: ", archimedesPiApprox(5))
print("Pi with 6 sides: ", archimedesPiApprox(6))
By trying different values, find the SMALLEST number of iterations to give pi correctly for the first 4 decimal values: 3.1415
Modify this program to use a loop to generate ALL approximations of pi between 3 and the result you found for the previous question.
Cut and paste this program into your Word document.
Make sure have answered all the questions. Submit your document to Moodle.