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

Programming Assignment Unit 2

Uploaded by

kuyembehj05
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)
7 views3 pages

Programming Assignment Unit 2

Uploaded by

kuyembehj05
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

Part 1: Circle Circumference Calculation

import math

def print_circum(radius):
"""
Calculates and prints the circumference of a circle given its radius.
Formula: circumference = 2 * π * radius
"""
circumference = 2 * math.pi * radius
print(f"The circumference of a circle with radius {radius} is
{circumference:.5f}")

# Function calls with different radius values


print_circum(5) # Radius = 5 units
print_circum(7.5) # Radius = 7.5 units
print_circum(10) # Radius = 10 units

Technical Explanation:
This function demonstrates:

1. Use of the math module to access π (pi) constant

2. A fruitful function that performs a calculation

3. String formatting to display results with 5 decimal places

4. Parameter passing with different argument types (integer and float)

Sample Output:
The circumference of a circle with radius 5 is 31.41593
The circumference of a circle with radius 7.5 is 47.12389
The circumference of a circle with radius 10 is 62.83185

Part 2: Online Store Catalog


def generate_catalog():
"""
Creates a product catalog with individual items and combo discounts.
Illustrates:
- Variable declarations
- Mathematical calculations
- String formatting
- Discount logic implementation
"""
# Product prices
item1 = 200.0
item2 = 400.0
item3 = 600.0
# Calculate combo prices with discounts
combo1 = (item1 + item2) * 0.9 # 10% discount
combo2 = (item2 + item3) * 0.9
combo3 = (item1 + item3) * 0.9
gift_pack = (item1 + item2 + item3) * 0.75 # 25% discount

# Display catalog
print("Online Store")
print("---")
print("Product(S)\tPrice")
print(f"Item 1\t\t{item1:.1f}")
print(f"Item 2\t\t{item2:.1f}")
print(f"Item 3\t\t{item3:.1f}")
print(f"Combo 1(Item 1 + 2)\t{combo1:.1f}")
print(f"Combo 2(Item 2 + 3)\t{combo2:.1f}")
print(f"Combo 3(Item 1 + 3)\t{combo3:.1f}")
print(f"Combo 4(Item 1 + 2 + 3)\t{gift_pack:.1f}")
print("\nFor delivery Contact:98764678899")

# Execute the function


generate_catalog()

Technical Explanation:
This solution demonstrates:

1. Variable assignment for product pricing

2. Arithmetic operations with discount calculations

3. String formatting for consistent output display

4. Business logic implementation (different discount tiers)

5. Function organization for code reusability

Output:
Online Store
---
Product(S) Price
Item 1 200.0
Item 2 400.0
Item 3 600.0
Combo 1(Item 1 + 2) 540.0
Combo 2(Item 2 + 3) 900.0
Combo 3(Item 1 + 3) 720.0
Combo 4(Item 1 + 2 + 3) 900.0

For delivery Contact:98764678899

References
Downey, A. (2015). Think Python: How to think like a computer scientist (2nd
ed.). Green Tea
Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf

University of the People. (2023). UoPeople APA Style


Guide. https://www.uopeople.edu

You might also like