Question

Python Practice Sample: Given the starter code: ITEM_COST = 302.48 TAX_RATE = 0.06 QUANTITY = 13...

Python Practice Sample:

Given the starter code:

ITEM_COST = 302.48

TAX_RATE = 0.06

QUANTITY = 13

NAME = "goodie"

CONTAINER = "bag"

Write a loop that prints the output formatted as below:

$ 320.63 goodie01bag

$ 641.26 goodie02bag

$ 961.89 goodie03bag

$ 1,282.52 goodie04bag

$ 1,603.14 goodie05bag

$ 1,923.77 goodie06bag

$ 2,244.40 goodie07bag

$ 2,565.03 goodie08bag

$ 2,885.66 goodie09bag

$ 3,206.29 goodie10bag

$ 3,526.92 goodie11bag

$ 3,847.55 goodie12bag

Note that the item name is formed by concatenating NAME followed by the string representation of a number between 1 and 12 followed by the CONTAINER. The string representation of the number is preceded by a 0 if the number is less than 10. The cost is the item cost multiplied by the corresponding quantity (1 through 12) multiplied by (1 + TAX RATE) The value is formatted right justified in a field of 9 with 2 after the decimal, and commas for values > 1000. A tab character separates the two values in each line. The amounts are right justified.

Homework Answers

Answer #1

Code:

ITEM_COST = 302.48 # given Cost 
TAX_RATE = 0.06 # tax rate
QUANTITY = 13   # quantity
NAME = "goodie" # name
CONTAINER = "bag"   # container
for i in range(1,QUANTITY):  # for loop to find the result
    ITEM_NAME = NAME+str(i).rjust(2,'0')+CONTAINER  # creating the name
    TOTAL_COST = ITEM_COST * (i) * (1+TAX_RATE) # calculating total cost
    COMMA_FORMAT = "{0:,.2f}".format(TOTAL_COST) # formatting the Value
    print('$'+str(COMMA_FORMAT).rjust(9,' ')+'\t'+ITEM_NAME ) # printing the result in given format with rjust of 9

Sample output:

Note: Please let me know if you have any doubt.

Know the answer?
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
Similar Questions
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). Extend...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). Extend the ItemToPurchase class per the following specifications              Private fields string itemDescription - Initialized in default constructor to "none" Parameterized constructor to assign item name, item description, item price, and itemquantity (default values of 0).             Public instance member methods setDescription() mutator & getDescription() accessor (2 pts) printItemCost() - Outputs the item name followed by the quantity, price, and subtotal printItemDescription() - Outputs the...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT