Starting from:

$29.99

IT5001 Assignment 1 – Hello Turtle! Solution


Required Files
• assignment1-template.py
Part 1: Closed form calculations
There are many kinds of equations to solve in algebra. One of the most common kind of equations are quadratic equations, which come in the form of π‘Žπ‘₯2 + 𝑏π‘₯ + 𝑐 = 0. In 628 AD, Brahmagupta explicitly described the general formula to be:
−𝑏 ± √b2 − 4ac x =
2a
Using Python, write out the expressions to get the roots of the equation πŸπŸŽπŸπŸŽπ’™πŸ + πŸπŸŽπŸŽπŸ—π± − πŸπŸŽπŸŽπŸ– = 𝟎, and assign them to variables ans1 and ans2.
Coursemology note: You do not have to implement the function checkAns. Your answer on Coursemology should have two lines, each line being an assignment statement to the variables ans1 and ans2 respectively. E.g. two lines of “ans1 = x + y + z”, “ans2 = 2*y + z”
In optics, refraction is a common phenomenon where light passes through two mediums of different refractive indexes. Snell’s law is a formula used to describe the relationship between the incoming and outgoing angles of light, as well as the refractive indexes of the mediums.
The equation for Snell's Law is described as:
𝑛1𝑠𝑖𝑛θ1 = 𝑛2𝑠𝑖𝑛θ2
where πœƒ1 is the incoming angle of incidence of light, πœƒ2 is the outgoing angle of refraction of light, 𝑛1 is the refractive index of the first medium, and 𝑛2 is the refractive index of the second medium.
Given the outgoing angle, π›‰πŸ = 𝟐𝟎∘, the refractive index of the incoming medium, water (π’πŸ = 𝟏. πŸ‘πŸ‘) and the refractive index of the outgoing medium, diamond (π’πŸ = 𝟐. πŸ’πŸπŸ•), write an expression to determine the incoming incidence angle IN DEGREES, and assign it to the variable ans.
Hint: What units does the sin function take in? The formula for converting degrees into radians is
radians = degrees
Coursemology note: Your answer on Coursemology should just have one line, an assignment statement to the variable ans.
Part 2: Simple Turtle
Some of the functions covered are:
- pd(): Pen down. Any movements thereafter will be traced
- pu(): Pen up. Any movements thereafter will NOT be traced
- forward(distance): Moves the turtle forward a number of units specified by distance
- backward(distance): Moves the turtle backward a number of units specified by distance
- right(degrees): Turns the turtle right by a certain number of degrees specified
- left(degrees): Turns the turtle left by a certain number of degrees specified
(Note: the direction functions forward, backward, right and left all have shorthands, which are fd, bk (or back), rt and lt respectively. Use whichever function you prefer.)
Warmup
In the following sequences of function calls, try to imagine what will be drawn. Then, run the calls yourself on Python. Did it draw what you had expected? (Note: This part is not graded and is only for your own practice. There is no need to copy your answers from this part to Coursemology)
a)
forward(100) backward(100) forward(100) backward(100) b)
backward(100) pu() left(90) forward(100) right(90)
forward(100)

c)
backward(100) left(90) forward(100) right(90)
forward(100)
d)
right(90) left(180) right(315) backward(100) right(90) backward(100)


With the functions that you have learnt so far, call a sequence of Turtle commands to draw an equilateral triangle with a distance of 300 units on each side, with the bottom of the triangle being parallel to the (imaginary) x-axis and the bottom left corner of the triangle corresponding to the starting point of Turtle. It should look something like this:

Coursemology note: Your answer on Coursemology should be a sequence of direction or movement functions, something like the following:
left(90)
right(90)
forward(100) backward(100)

More products