Write my Essay on Python Homework Help

UNIT E TAKE-HOME ASSIGNMENT

At the top of each of your problems put the following multi-line comment, with your information:

”’
Your name as registered, with optional nickname in parentheses
CIS 41A Fall 2017
Unit E take-home assignment
”’

THIS ASSIGNMENT CONSISTS OF FIVE SEPARATE SCRIPTS.

All five scripts should consist of a main function that includes a call to a function that includes the code.

FIRST SCRIPT:

Write an invoicing function. The function will generate a simple invoice and will have two required arguments and two keyword arguments – see: keyword arguments
The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5.

Test it twice: first with a unitPrice of 20, a quantity of 4, and shipping of 8 (handling is not specified). Test a second time with a unitPrice of 15, a quantity of 3, and handling of 15 (shipping is not specified). Don’t worry about making the formatting pretty.

Sample Execution Results:

Cost (unitPrice x quantity) = 45
Shipping = 10
Handling = 15
Total = 70
SECOND SCRIPT:

Write a uniqueList function. Create a list with ten random but unique elements ranging from 1 to 15 inclusive. Print the sorted list and the sum of its values. Hint: Use a while loop. Within the loop, generate random numbers using randint. If the number isn’t already in the list, add it to the list. Loop until you have 10 numbers in the list.

Sample Execution Results:

[1, 4, 6, 7, 8, 9, 11, 12, 13, 15]
Sum = 86
THIRD SCRIPT:

Write a rangeList function. Create a list of all even numbers from 50 to 60 inclusive (Hint: generate the numbers with the appropriate range and convert the range to a list with the list function). Shuffle the list – see: functions for sequences
Print the list. Find and print the index of the first list element that is less than 53.

Sample Execution Results:

[50, 60, 56, 52, 54, 58]
Index of first list element less than 53 is: 0
FOURTH SCRIPT:

Write a sliceList function. Create a list of the integers from 1 to 10 inclusive (again, build the list from a range). Loop through a slice of the list to print the numbers 5 through 7 inclusive.

Sample Execution Results:

5
6
7
FIFTH SCRIPT:

Write a diceTest function (and also use the rollDie function that you wrote for the in-class exercise). The function will simulate rolling two six-sided dice 100,000 times. Create a list called rollResults that contains 13 zeros. We will use this list as a set of “buckets” to count how many times a particular dice total occurs. For example, if a 6 and a 4 are rolled (totaling 10), increment rollResults[10] by one. After populating the rollResults list, loop through the list and print the results, converting them to a percentage.

Sample Execution Results:

Chance of rolling a 0 0.0%
Chance of rolling a 1 0.0%
Chance of rolling a 2 2.85%
Chance of rolling a 3 6.02%
Chance of rolling a 4 8.2%
Chance of rolling a 5 11.02%
Chance of rolling a 6 13.48%
Chance of rolling a 7 16.54%
Chance of rolling a 8 14.3%
Chance of rolling a 9 10.89%
Chance of rolling a 10 8.12%
Chance of rolling a 11 5.75%
Chance of rolling a 12 2.83%
For each script add the following at the end, showing your results:

”’
Execution results:
paste execution results here
”’

Print and staple together the five scripts, including the execution results, and turn them in.

UNIT F

IN-CLASS ASSIGNMENT

Chapter 5: Functions continued

Chapter 6: Lists continued

This assignment has two parts.

Part 1 of 2 – How Python function arguments are treated:

There can be some confusion as to how Python functions treat their arguments – is it by reference or by value? Various resources (including the Python for Everyone textbook) do an inadequate job of explaining this. Explore this for yourself – in main, create a myInt variable and give it the value 3. Also create a myList list and give it the values 0,1,2.

Print the IDs of myInt and myList. Use the id function – see: id function
Also print the ID of the last element of myList.
Now create a function called byVal which has one argument. In the function, add 7 to the argument. Print the ID of the argument before and after the change.

Create a second function called byRef which has one argument. In the function, add 7 to the last element in the list. Print the ID of the argument and the ID of the last element of the argument before and after the change.

Now call byVal with myInt and then call byRef with myList. Next, again print the IDs of MyInt, myList, and the last element of myList. Finally, print myInt and MyList from main. Can you explain the results? Here are two sites that do a good job of explaining how Python functions work:
Is Python call-by-value or call-by-reference? Neither.
Parameter passing

Sample Execution Results:

Original ID of myInt in main is 1482185008
Original ID of myList in main is 28658584
Original ID of myList’s last element in main is 1482184992
Original ID of parameter in byVal 1482185008
ID of parameter in byVal after change 1482185120
Original ID of parameter in byRef 28658584
Original ID of parameter’s last element in byRef 1482184992
ID of parameter in byRef after change 28658584
ID of parameter’s last element in byRef after change 1482185104
ID of myInt in main after call to byVal is 1482185008
ID of myList in main after call to byRef is 28658584
ID of myList’s last element in main after call to byRef is 1482185104
myInt is now: 3
myList is now: [0, 1, 9]
Part 2 of 2 – Ragged Table:

Write two functions that will build and display a Bell triangle – see: What is a Bell triangle

A Bell triangle can be constructed with the following algorithm:

The first row has a single element which has the value 1.
The nth row has a length of n.
For all subsequent rows, the first element is equal to the last element of the previous row.
Additionally, for all subsequent rows, the second through nth elements are calculated by adding the value of the previous element (n-1) in the current row to the (n-1) element of the previous row.
As an example of this calculation, start by looking at the triangle shown below. To calculate the 3rd element of the 4th row, we add the 2nd element of the 4th row (7) to the 2nd element of the 3rd row (3), with the total being 10.

The first function should be called buildBell. It has one argument, the number of rows, and returns a ragged table (a list of lists).

The second function should be called printBell. It has one argument, a ragged table (a list of lists). Generate formatted output where each number is right justified within a fixed field size, so that the numbers in each column are aligned.

Test by calling buildBell from main to build a Bell triangle with 8 rows.

Then call printBell from main to print the triangle.

Sample Execution Results with 6 rows:

1
1 2
2 3 5
5 7 10 15
15 20 27 37 52
52 67 87 114 151 203

The post Python Homework Help appeared first on Essaysholic.

Would you like to get in touh with us?
Contact Us

Is this question part of your Assignment?

We can help

Our aim is to help you get A+ grades on your Coursework.

We handle assignments in a multiplicity of subject areas including Admission Essays, General Essays, Case Studies, Coursework, Dissertations, Editing, Research Papers, and Research proposals

Header Button Label: Get Started NowGet Started Header Button Label: View writing samplesView writing samples