Plz help me finish these last two questions for computer science :(

plz help me finish these last two questions for computer science 🙁 Using Python v2


The Lesson:

Functions & Turtles
There are many ways to do graphics in Python, using the “turtle” module is one of the easiest. Turtle graphics are a fun way to review the use of functions. Load the code below into Wing and see what happens:

# This program will draw an angled line
import turtle

turtle.color(“blue”) # colour will be blue
turtle.up() # pick up the pen

turtle.setx(0) # put the x coordinate of the pen at 0
turtle.sety(0) # put the y coordinate of the pen at 0
turtle.down() # put the pen down

deg = 45
turtle.right(deg) # turn right the specified number of degrees
turtle.forward(200) # move the turtle forward a distance of 200

turtle.up() # pick up the pen
turtle.goto(-150,-120) # go to this coordinate position
turtle.color(“red”) # change the colour
turtle.write(“Done!”) # print the Done message.

You will see that a line is drawn in the “turtle” window.
> setx and sety represent the horizontal and vertical axes
> the turtle.color function can either take 3 arguments (red, green, blue – each a floating point value between the value of 0 and 1 to represent a specific shade of colour) or a value of “red”, “green”, or “blue”.
> For the other turtle functions see the associated comments

What if we want to draw additional lines? This is where the use of functions can be very useful. Rather than retyping the code over and over, we could just pass parameters to a function, and get different colours and line orientations. See the example below:


# This program will draw an angled line
import turtle

def draw_angled_line():

turtle.color(“blue”) # colour will be blue
turtle.up() # pick up the pen

turtle.setx(0) # put the x coordinate of the pen at 0
turtle.sety(0) # put the y coordinate of the pen at 0
turtle.down() # put the pen down

deg = 45
turtle.right(deg) # turn right the specified number of degrees
turtle.forward(200) # move the turtle forward a distance of 200

turtle.up() # pick up the pen
turtle.goto(-150,-120) # go to this coordinate position
turtle.color(“red”) # change the colour
turtle.write(“Done!”) # print the Done message.

draw_angled_line()
What is the problem with this? Let’s fix it!


# This program will draw an angled line
import turtle

def draw_angled_line(x, y):

turtle.color(“blue”) # colour will be blue
turtle.up() # pick up the pen

turtle.setx(x) # put the x coordinate of the pen at 0
turtle.sety(y) # put the y coordinate of the pen at 0
turtle.down() # put the pen down

deg = 45
turtle.right(deg) # turn right the specified number of degrees
turtle.forward(200) # move the turtle forward a distance of 200

turtle.up() # pick up the pen
turtle.goto(-150,-120) # go to this coordinate position
turtle.color(“red”) # change the colour
turtle.write(“Done!”) # print the Done message.

draw_angled_line(0, 0)
draw_angled_line(20,20)

Note how x and y parameters are passed to the function. Recalling this function with diffierent parameters will only require one additional line of code for each line drawn on the screen.

We can make this function easier to write by using one command at the top of your file from turtle import * . This command has the Python interpreter think that all of the turtle function definitions are in your program so it does not have to go out and find the turtle module somewhere else. Here’s how to do it:

# This program will draw an angled line
from turtle import *

def draw_angled_line(x, y, r, g, b):

color(r, g, b) # set the colour
up() # pick up the pen

setx(x) # put the x coordinate of the pen at 0
sety(y) # put the y coordinate of the pen at 0
down() # put the pen down

deg = 45
right(deg) # turn right the specified number of degrees
forward(200) # move the turtle forward a distance of 200

up() # pick up the pen
goto(-150,-120) # go to this coordinate position
color(“red”) # change the colour
write(“Done!”) # print the Done message.

draw_angled_line(0, 0, 0,1,0) # begins at (0,0), colour is green
draw_angled_line(20,20, 0, 0.5, 0.5) # begins at (20,20), colour is a mix of green and blue

Turtle Function Description
color(val) Sets the colour of the pen
up() Lifts the pen up(so no colour shows on the screen)
down() Puts the pen down on the screen
setx(val) Positions the pen’s x position
sety(val) Positions the pen’s y position
right(degree) Turns right the specified number of degrees
forward(val) Move forward a distance specified by val
goto(x) Go to the coordinate specified by (x,y)
write(string) Print out string onto the screen




The Assignments:
3. Using turtle graphics function example above (without the height variable):
a) Create a square by passing the appropriate parameters. Make each side of the square a different color.
b) Create a triangle by passing the appropriate parameters.

4. Using turtle graphics define two functions to create the following shapes:

draw_star(): define a function to draw 8 lines at equally spaced angles in the 4 quadrants of the Cartesian plane (45 degrees apart from each other). (Hint: use a for loop)
draw_square_patterns(): define a function to draw 8 squares shifted at a 45 degree angle from each other. (Hint: use a for loop)

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more