Prog Unit2
Prog Unit2
Kevin Kipkirui
PART 1
Here’s how to create the function print_circum in Python, along with an explanation of
# Function definition
def print_circum(radius):
pi = 3.14159
circumference = 2 * pi * radius
is {circumference:.5f}")
1. Function Definition:
decimal places.
2. Circumference Calculation:
3. Output Formatting:
places.
4. Function Calls:
Expected Output
Technical Explanation
Output: Each call to the function prints the calculated circumference directly to the
console.
PART 2
Here is a custom Python function for the provided scenario, with an explanation and the
expected output:
Code:
def generate_catalog():
item1_price = 200.0
item2_price = 400.0
item3_price = 600.0
print("Online Store")
print("-------------------")
print("Product(S) Price")
print(f"Item 1 {item1_price}")
print(f"Item 2 {item2_price}")
print(f"Item 3 {item3_price}")
print("-------------------")
generate_catalog()
Output:
Online Store
-------------------
Product(S) Price
Item 1 200.0
Item 2 400.0
Item 3 600.0
-------------------
1. Input Values:
o The base prices for Item 1, Item 2, and Item 3 are stored in variables.
2. Discount Calculations:
o For combos with two items, a 10% discount is applied (price * 0.9).
o For the gift pack with all three items, a 25% discount is applied (price * 0.75).
3. Dynamic Formatting:
o Formatted output ensures proper alignment and displays prices with a single
4. Features Illustrated:
o Modular design using a single function to define and display catalog details.
1. Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree
Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf
3. Sweigart, A. (2020). Automate the boring stuff with Python: Practical programming