0% found this document useful (0 votes)
20 views3 pages

Assignment 2 U0P

The document contains two code examples that calculate circle circumferences and online store prices. The first defines a print_circum function that calculates and prints the circumference of circles with different radii. The second defines a company_cat function that calculates individual item prices, combo prices with a 10% discount, and a gift package price with a 25% discount and prints an output listing the items and prices. Both functions are called to produce the expected output.

Uploaded by

winsingglobal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Assignment 2 U0P

The document contains two code examples that calculate circle circumferences and online store prices. The first defines a print_circum function that calculates and prints the circumference of circles with different radii. The second defines a company_cat function that calculates individual item prices, combo prices with a 10% discount, and a gift package price with a 25% discount and prints an output listing the items and prices. Both functions are called to produce the expected output.

Uploaded by

winsingglobal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise 1:

def print_circum(radius):
circumf = 2 * 3.14159 * radius
print ("The circumference of this circle with a radius of", radius, "is", circumf)
print_circum (5)
print_circum(10)
print_circum(2.5)
Output:
The circumference of this circle with a radius of 5 is 31.4159
The circumference of this circle with a radius of 10 is 62.8318
The circumference of this circle with a radius of 2.5 is 15.70795
>
Explanation: I created a function named print_circum() which holds a parameter called
‘radius'. I also created a local variable called ‘circumf' which holds the formula for
calculating the circumference of a circle using pi as 3.14159 and what ever argument passed
by the user as the radius. Finally I printed out an output which displays the result after
calculation.
I called my created function thrice passing 3 different arguments and it printed out the correct
answers of the circumference of each circle taking into consideration there various radius

Exercise 2:
def company_cat():
item_price1 = 200.00
item_price2 = 150.00
item_price3 = 300.00
mix_price1 = item_price1 + item_price2 - 0.1 * (item_price1 + item_price2)
mix_price2 =item_price2 + item_price3 - 0.1 * (item_price2 + item_price3)
mix_price3 =item_price1 + item_price3 - 0.1 * (item_price1 + item_price3)
gift_package_price = item_price1 + item_price2 + item_price3 - 0.25 * (item_price1 +
item_price2 + item_price3)
print("Online Store")
print("‐-------------------")
print("Product(s) Price")
print(f"Item 1", {item_price1})
print(f"Item 2", {item_price2})
print(f"Item 3", {item_price3})
. print(f"Combo 1. Item 1 + 2", mix_price1)
print(f"Combo 2. Item 2 + 3", mix_price2)
print(f"Combo 3. Item 1 + 3", mix_price3)
print(f"Combo 4. Item 1 + 2 + 3", gift_package_price)
print("---------------------")
print(" For delivery contact 98764678899")
company_cat()

Output:
Online Store
‐-------------------
Product(s) Price
Item 1 200.0
Item 2 150.0
Item 3 300.0
Combo 1. Item 1 + 2 315.0
Combo 2. Item 2 + 3 405.0
Combo 3. Item 1 + 3 450.0
Combo 4. Item 1 + 2 + 3. 487.5
---------------------
For delivery contact 98764678899
>

Explanation: I created a function called company_cat() which contains 3 local variables


called item_price1, item_price2, item_price3. These variables holds the price value of each
item sold by the company. I further created 3 more variables to hold the combo item
purchases of customers taking into consideration the 10% discount on the combo item and
25% on the gift pack. I printed an output which shows the individual items and prices, the
combo and prices and the gift pack and its price. At the end i called the company_cat()
function to get a final output.

You might also like