COMP 141 Project 2: Darts

You are playing a strange game of darts with a square board that looks like the image below. Pretend there is a grid on the board similar to the regular x-y Cartesian coordinate system. The lower left corner of the board is at position (0, 0) and the upper right corner is at (30, 30).

You earn points in this game of darts depending on what color the square is that you hit. Red squares are worth 5 points, yellow squares are 10 points, and green squares are 15 points. If the dart lands off the board, no points are earned.

What you need to do

Write a complete Python program that asks the user where their dart landed and prints out how many points they win for that dart, according to the dart board diagram above. Your program only has to handle a single dart. Your program should gracefully handle cases where the dart lands off the board by printing a message saying that no points were won.

You may work with ints or floats. You should assume that if the dart lands on a vertical dividing line, the points are awarded for the region to the right, and if the dart lands on a horizontal dividing line, the points are awarded for the region above.

You should define a main() function for your program. You do not need to use any other functions unless you so desire. (The primary point of this program is to test your if/else skills; there will be other programs later to test your function skills.)

Test your program on lots of examples, including the sample ones below, and make sure they work correctly. Your program should work correctly for all reasonable inputs, not just the sample ones below.

Make sure to include comments in your code that describe what the program does as a whole, what each separate function does, and what any complicated sections of code do. You should feel free to use more comments if you so desire. Follow the instructions in the comment guide.

Sample Interactions

What the computer displays (prints) is in regular text, what the user types is in bold, and what the program is doing behind the scenes is in italics.

Test 1

(Program begins) What is the x-coordinate where your dart landed? 5 What is the y-coordinate where your dart landed? 9 (Program determines the dart is in a red region.) You win 5 points! (Program ends)

Test 2

(Program begins) What is the x-coordinate where your dart landed? 20 What is the y-coordinate where your dart landed? 10 (Program determines the dart is in a yellow region.) You win 10 points! (Program ends)

Test 3

(Program begins) What is the x-coordinate where your dart landed? 25 What is the y-coordinate where your dart landed? 0 (Program determines the dart is in a green region.) You win 15 points! (Program ends)

Test 4

(Program begins) What is the x-coordinate where your dart landed? -1 What is the y-coordinate where your dart landed? -1 (Program determines the dart is off the board.) You win 0 points! (Program ends)

Test 5

(Program begins) What is the x-coordinate where your dart landed? 100 What is the y-coordinate where your dart landed? 150 (Program determines the dart is off the board.) You win 0 points! (Program ends)
Your code does not need to follow this script verbatim, but all the mentioned functionality should work as shown.

Hints

What to turn in

Through Moodle, turn in your code as a file called darts_yourLastName_yourFirstName.py.

Challenge Problems

From time to time, I will offer "challenge problems" on assignments. These problems are designed to have little (but some) impact on your grade whether you do them or not. You should think of these problems as opportunities to work on something interesting and optional, rather than a way to raise your grade through "extra credit."

Policy on challenge problems:

Challenge problem for this assignment: