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

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

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_x000D_
Shipping = 10_x000D_
Handling = 15_x000D_
Total = 70_x000D_

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]_x000D_
Sum = 86_x000D_

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]_x000D_
Index of first list element less than 53 is: 0_x000D_

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:


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%_x000D_
Chance of rolling a 1 0.0%_x000D_
Chance of rolling a 2 2.85%_x000D_
Chance of rolling a 3 6.02%_x000D_
Chance of rolling a 4 8.2%_x000D_
Chance of rolling a 5 11.02%_x000D_
Chance of rolling a 6 13.48%_x000D_
Chance of rolling a 7 16.54%_x000D_
Chance of rolling a 8 14.3%_x000D_
Chance of rolling a 9 10.89%_x000D_
Chance of rolling a 10 8.12%_x000D_
Chance of rolling a 11 5.75%_x000D_
Chance of rolling a 12 2.83%_x000D_

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_x000D_
Original ID of myList in main is 28658584_x000D_
Original ID of myList's last element in main is 1482184992_x000D_
Original ID of parameter in byVal 1482185008_x000D_
ID of parameter in byVal after change 1482185120_x000D_
Original ID of parameter in byRef 28658584_x000D_
Original ID of parameter's last element in byRef 1482184992_x000D_
ID of parameter in byRef after change 28658584_x000D_
ID of parameter's last element in byRef after change 1482185104_x000D_
ID of myInt in main after call to byVal is 1482185008_x000D_
ID of myList in main after call to byRef is 28658584_x000D_
ID of myList's last element in main after call to byRef is 1482185104_x000D_
myInt is now: 3_x000D_
myList is now: [0, 1, 9]_x000D_
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:

  1. The first row has a single element which has the value 1.
  2. The nth row has a length of n.
  3. For all subsequent rows, the first element is equal to the last element of the previous row.
  4. 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    2_x000D_
    2    3    5_x000D_
    5    7   10   15_x000D_
   15   20   27   37   52_x000D_
   52   67   87  114  151  203

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.