Question

Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have...

Use python!!! need to match the execution result that is provided.

Part One – Keyword Arguments and Default Values

Write an invoice function.
The function will generate a simple invoice and will have two required arguments and two 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 from main:
First test: unitPrice 20, quantity 4, and shipping 8 (handling is not specified).
Second test: unitPrice 15, quantity 3, and handling 15 (shipping is not specified).
Don't worry about making the formatting pretty.

Part Two – args (Variable-Length Arguments)

Write a printGroupMembers function.
The function prints a list of students who are working together on a group project, as well as the group name.
The function has one required argument, the group name, and one variable-length argument that contains the student names.

Test it twice from main:
First test: Call as follows:
printGroupMembers("Group A", "Li", "Audry", "Jia")
Second test: Create a list as follows:
groupB = ["Group B", "Sasha", "Migel", "Tanya", "Hiroto"]
and then call the function using this list.

Part Three – Non-Rectangular (Ragged) 2D lists

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

A Bell triangle can be constructed as follows:

  1. The first row has a single element which has the value 1.
  2. For the second row and all subsequent rows:
  3. The number of elements in a row is equal to the number of elements in the previous row + 1.
  4. The first element in the row is equal to the last element of the previous row.
  5. The second through nth elements of a row 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 (n=3) element of the 4th row, we add the 2nd (3-1=2) element of the 4th row (7) to the 2nd (3-1=2) element of the 3rd row (3), with the total being 10 (7+3=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.

Hint: The easiest way to format the numbers is probably by using the rjust string function.

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

Then call printBell from main to print the triangle.

Example output:

Cost (unitPrice x quantity) = 80
Shipping = 8
Handling = 5
Total = 93

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

Members of Group A
Li
Audry
Jia
Members of Group B
Sasha
Migel
Tanya
Hiroto

    1
    1    2
    2    3    5
    5    7   10   15
   15   20   27   37   52
   52   67   87  114  151  203
  203  255  322  409  523  674  877
  877 1080 1335 1657 2066 2589 3263 4140
0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here are the code for the first two functions, the 3rd question is somewhat unclear. Could you please clarify or rephrase it so that i can answer it.

====================================================================================

def invoice(unitPrice,quantity,shipping=10,handling=5):
    return unitPrice*quantity + shipping+handling

print(invoice(20,4,8))
print(invoice(15,3,handling=15))



def printGroupMembers(groupname,*names):
    if len(names) is not 0:
        print(groupname)
        for name in names:
            print(name)
    else:
        for name in groupname:
            print(name)
printGroupMembers('Group A','Li','Audry','Jia')
printGroupMembers(['Group B','Sasha','Migel','Tanya','Hiroto'])

def invoice (unit price, quantity, shipping 10, handling#5): return unitPrice quantity shipping+handling print (invoice (20,

Add a comment
Know the answer?
Add Answer to:
Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT