From the course: Python Practice: Real-World Coding Challenges

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: Plotting the course

Solution: Plotting the course

(upbeat music) - [Instructor] To start, I added a function to the terminal scribe called plotX, which iterates through the numbers on the x axis in the graph and returns the corresponding y value at each point and you can see it gets the next position as x, function x, calling the function that gets passed in as an argument, and this will probably seem very familiar from your algebra days where you know y is a function of x. Then of course we check to see if this new position hits a wall, and if so we just skip it. The function that I'm passing in is down here and that is five times sine of x over four plus 10 which I've designed to be a sine wave that looks nice on the size of canvas that I'm using. I've also written the corresponding cosine function five times math, cosine x over four plus 10 which we can draw at the same time. So let's go check it out. There's the sine and the cosine. Beautiful.

Contents