Assignment 01

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Programming Assignment Unit 2

Part 1:

Part 2:

Explanation:

The code below is the catalog of a small company called Online Store. This company sells three

items at the price of 200, 400, and 600 and offers a discount when a customer buys two or more

items at the same time. To build this catalog, first I printed the name and created three variables

by the name of item_one, item_two, and item_three, which store the values of the price item. For

developing combos and applying discounts, I have used functions to do it. The first function is

called combo_one and has 2 parameters (item 1 and item 2). This function adds items 1 and 2
and then adds a 10% discount to the total price of them and finally prints the final output.

Moreover, I have used the format method in Python to display the output on screen with spaces

between them. Str.format in Python allows you to concatenate elements together through

positional formatting and perform value formatting on variables (Tagliaferri, 2021).

print("Combo 1(Item 1 + 2)", "{:17.1f}".format(combo))

Here, I am printing a string “Combo 1(Item1 + item2)” and "{:17.1f}", 1f means that in show

one digit after the dot in a float point, and :17 puts 17 spaces between the string and combo.

Moreover, I have created another function named combo_two, which again takes two arguments.

This function adds the value of item_two and item_three and then applies a 10% discount to the

total amount, and lastly prints a result after the discount. The same formatting condition is

applied to this function as well. Moreover, the third function is called combo_three with two

parameters, item1 and item2. This function adds the value of item_three and item_one, adds a

10% discount to them, and prints the final result. Lastly, the last function is called

combo_special, and it takes three arguments. This function adds all the prices three times and

adds a 25% discount to them according to the company policy, and then prints the result after the

25% discount. This function has the same formatting style as mentioned above and uses the

str.format method.

Firstly, the prices of items are displayed with their names because if a customer buys one item,

the company has no discount; if the customer buys two items, they get 10%. The combo 1,

combo 2, and combo 3 apply 10% to them and calculate the final price. Finally, if the customers

buy all three products, they get a 25% discount, and combo_special calculates it.
Refernces:

Tagliaferri, L. (2021, August 20). How To Use String Formatters in Python 3.

Https://www.Digitalocean.com/. Retrieved February 13, 2024, from

https://www.digitalocean.com/community/tutorials/how-to-use-string-formatters-in-

python-3

You might also like