Starting from:
$35

$29

Introduction to Programming Assignment 2 Solution

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)

    1. Create 2 lists representing 2 x-y points – save them in variables p1 & p2:

p1 = [1.4, 5.2]

p2 = [7.8, 1.6]

    2. Write the Python expression to calculate the distance between these 2 points (use the “distance formula”)

    3. Save the distance value in a variable

    4. Print the variable



Problem B)

    1. Assume 1 can of paint covers 250 square feet of wall.

    2. 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].

    3. Assume the walls are 10 feet tall.

    4. 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.

    5. Part of your grade on this will be the efficiency of how you calculate this.


Problem C)

    1. 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.

    2. Write the Python code to prompt the user to enter an x and y coordinate for a new 3rd point

    3. Using the input values, create lists representing the new X-Y point

    4. 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)

    1. 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)

    1. 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.

    2. Add a docstring to your function (for use in “help(average)”).

    3. Ask the user to enter the number of scores they want to enter.

    4. Create a new (empty) list.

    5. 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.

    6. Once the data entry is done, call your “average” by passing it the new list you just filled.

    7. 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.

    • 

More products