Curve
Computer displays are made up of a grid of tiny lights. Because the displays are not continuous, curved objects must be broken into many non-continuous pieces. So curves are often simply represented as many straight lines. In this activity you will approximate a curve by drawing many lines.
Details
Create a Python program that uses the turtle module to draw a curve using overlapping straight lines between the x-axis and the y-axis. The program should prompt the user to enter the number of lines to draw and the length axes .
Example
Enter the number of lines: 5 Enter the length of the axes: 100

Enter the number of lines: 10 Enter the length of the axes: 100

- You want to use the new range values for this activity. You need to determine how much space to be between consecutive points on the lines. This will be the step amount for your loop.
- Drawing the curve is much easier if you use the
function
turtle.goto
. - For each line, calculate the coordinates of both end points
- Use the
turtle.goto
function to move the turtle to the start point, then use theturtle.goto
function again to move the turtle to the end point. - Note that you may need to use the
turtle.up
andturtle.down
functions to prevent the turtle from drawing a line when it moves to the line's start end point.
Challenge
This same technique can be used to draw a myriad of different curves, by changing the length and angle of the axes. Add variable to your program that specify the length and angle of each of the axes to create curves like the following.

You can even put the code that draws the curve in a loop to draw multiple curves.

Pyramids
Before computers were capable of displaying graphics, programs could draw using ASCII characters. More recently, with the help of programs, artistss have created intricate ASCII Art.
Details
Create a Python program that prints a pyramid of asterisks. The program should prompt the user for the number of levels to print. Note, the program should not use the string repeat operator.
Example
Enter the number of levels: 3 * * * * * *
Enter the number of levels: 6 * * * * * * * * * * * * * * * * * * * * *
- This program is going to need a total of 3 loops, two loops nested inside another loop. The outer for loop will execute for the number of levels in the pyramid. The first for loop inside the outer loop prints the spaces that preceed the askerisks on that level. The second loop inside the outer loop prints asterisks.
- The number of askerisks is directly related to the level of the pyramid. If the top of the pyramid is level 1, then the number of asterisks is the same level number.
- The number of spaces is inversely related to the level of the pyramid. If the top of the pyramid is level 1, then the number of spaces is the number of levels minus the level number.
-
In order to get multiple things printed on a single line in python, we have to take advantage of a special option of the print function called end. end lets us specify what appears at the end of the statement we want printed, and defaults to the newline character.
If I don't want a newline at the end of my print statement, I just change the value of end in my call to the print function:
print("anything", "to", "print", end="")
When you want to add a new line later in your program, you can simply call print again.
Challenge
Using turtle and
the stamp
method, create a graphical version of the pyramid. You can change
the shape of the turtle using
the shape
command.
