CPSC 120 B




Lecture
MWF 10:50am - 11:50am
Lab
MWF 12:00pm - 1:00pm

Scotty Smith

Office
Trexler 365-B
Office Hours
Monday / Thursday
3:00pm - 5:00pm
Email
chssmithATroanoke.edu

< Back
Printable Copy

Lecture 20 - Problem Solving


As usual, create two directories for today's class. Create a directory called lecture20 under activities, and a directory called lab20 under labs.


Randomizer!

Time to spin the wheel and find out what you will be submitting for your final portion of this weeks quiz grade.


In-Class Activity 1

Guessing Game

Create a file called guessing_game.py in your lecture20 directory. The program in this file should generate a random number, and prompt the user to enter a guess of the number. The user should be allowed to keep guessing until they get the guess correct.

Your program should indicate if the users guess is higher or lower than the randomly selected value.

Challenge After the user guesses twice, your program should indicate whether the user is getting warmer or colder compared to their previous guess.

Lazy Programming

I've been forcing you to do a lot of things this semester, and most of you are not sure exactly why. Let's spend some time exploring how to approach solving problems.


In-class Activity 2

Point in Triangle

Read the following mini-assignment prompt. I will go through the "lazy" solution in class.

Create a program that draws a triangle and a random point and tests if the point is inside the triangle. The program should draw a triangle that takes up the majority of the window. You can pick the location of each of the corners, or vertices, of the triangle. The program should also generate and draw a random point in the window. The color of the circle should be determined by whether the point is inside or outside the triangle.

A point is inside a triangle if it is on the interior side of all three edges of the triangle. For example, the point P in the illustration below is on the interior side of the edge from B to C and the edge from C to A, but it is not on the interior side of the edge from A to B.