What's new

Python I need help po with my python Assignment , need po source code and explanation

paulghette1026

Honorary Poster
Established
Joined
Aug 27, 2017
Posts
433
Reaction
110
Points
213
Welcome to your first project. Develop a catalog for a company. Assume that this company sells three different Items. The seller can sell individual items or a combination of any two items. A gift pack is a special combination that contains all three items. Here are some special considerations:

A. If a customer purchases individual items, he does not receive any discount.
B. If a customer purchases a combo pack with two unique items, he gets a 10% discount.
C. If the customer purchases a gift pack, he gets a 25% discount.

Write a function for the above scenario. Perform the calculations in code wherever applicable. . The final output should look like:

1695298160693.png

Include the following in your part 2 submission:



  • The code for the function that you created.
  • The Output of the code.
  • A description of what feature(s) your function illustrates.
  • The code and its output must be explained technically. The explanation can be provided before or after the code, or in the form of comments within the code.
If you use an informational source, be sure to identify the source and share the link to the source you used.


I need help po on this until tomorrow nlng po pasahan ng 1pm | Salamat po sa makakahelp
 

Attachments

Sure, I can help you with that. Here's the code for the function that calculates the total price based on the given discounts:

Python:
def calculate_total_price(item1, item2, item3):
    # Calculate the individual prices of the items
    item1_price = 100
    item2_price = 200
    item3_price = 300

    # Calculate the total price without any discount
    total_price = item1_price*item1 + item2_price*item2 + item3_price*item3

    # Check if the customer purchased a combo pack with two unique items
    if item1 + item2 + item3 == 2 and (item1 != 0 and item2 != 0 and item3 != 0):
        total_price *= 0.9  # Apply 10% discount

    # Check if the customer purchased a gift pack
    if item1 + item2 + item3 == 3:
        total_price *= 0.75  # Apply 25% discount

    return total_price

To use the function, you need to pass the quantities of each item as arguments. For example, if the customer purchased 2 of the first item, 1 of the second item, and 0 of the third item, you can call the function like this:

Python:
total_price = calculate_total_price(2, 1, 0)
print(total_price)

The output will be the total price after applying the discounts.

Explanation:
  • The function calculate_total_price takes three arguments representing the quantities of each item.
  • The individual prices of the items are defined as constants (item1_price, item2_price, item3_price).
  • The total price is calculated by multiplying the quantities of each item with their respective prices and summing them up.
  • If the customer purchased a combo pack with two unique items, the total price is reduced by 10%.
  • If the customer purchased a gift pack (i.e., all three items), the total price is reduced by 25%.
  • The final total price is returned by the function.

In the example above, the customer purchased 2 of the first item, 1 of the second item, and 0 of the third item. The total price is calculated as follows:

Code:
total_price = (2 * 100) + (1 * 200) + (0 * 300) = 500

Since the customer didn't purchase a combo pack or a gift pack, there is no discount applied. Therefore, the output will be 500.

Let me know if you need further assistance or explanation.
 
Back
Top