Description
Your assignment is to solve the following problems (A – D) in Python. Problem E can optionally be done for extra credit (10 pts). You can add all these to the same python file, edited and executed via the Python IDLE interface.
Problem A)
-
Create 2 lists representing 2 x-y points – save them in variables p1 & p2:
p1 = [1.4, 5.2]
p2 = [7.8, 1.6]
-
Write the Python expression to calculate the distance between these 2 points (use the “distance formula”)
-
Save the distance value in a variable
-
Print the variable
Problem B)
-
Assume 1 can of paint covers 250 square feet of wall.
-
Write the python code to determine how many cans of paint I need to buy to cover the 6 walls in this floorplan. Your solution must put the wall widths in a list (i.e., [8, 4, 4, 6…etc].
-
Assume the walls are 10 feet tall.
-
Ignore the fact that there would probably be doors and windows. You do not need to account for those – just use the full wall dimensions.
-
Part of your grade on this will be the efficiency of how you calculate this.
Problem C)
-
Assume the 2 points from problem “A” are two opposite corners of a rectangle, where P1 is the upper-left and P2 is the lower-right. Use that assumption in the problem to do the following.
-
Write the Python code to prompt the user to enter an x and y coordinate for a new 3rd point
-
Using the input values, create lists representing the new X-Y point
-
Your program should then print true or false based on whether the 3rd point lies within the rectangle spanned by P1 and P2.
Example: P1 •
• user point 2
-
user point 1
Problem D)
-
Write the python code to put all numbers divisible by 6 but not divisible by 4 from 1 through (and including) 150 into a list, then print the list.
Extra Credit (optional)
Problem E)
-
Write a python function “average” that accepts a list parameter (a list of student scores), and returns the average of the values in the list. Assume the list will contain numeric values. Next, we will use that function.
-
Add a docstring to your function (for use in “help(average)”).
-
Ask the user to enter the number of scores they want to enter.
-
Create a new (empty) list.
-
Using the number of scores (and a “for” loop), ask the user to enter each score. Add each score to the new list you created.
-
Once the data entry is done, call your “average” by passing it the new list you just filled.
-
Print the average that it calculated.
Submission
-
Your submission should consist of your Python “.py” file, submitted via D2L.
-
This assignment is due (submitted via D2l) before the start of class in 1 week
-
NO LATE ASSIGNMENTS CAN BE ACCEPTED.