CS 1101 Programming Assignment 2
CS 1101 Programming Assignment 2
PART 1
INPUT
import math
def print_circum(radius):
"""Calculates and prints the circumference of a circle given its radius."""
circumference = 2 * math.pi * radius
print(f"The circumference of a circle with radius {radius} is: {circumference:.5f}")
# Calling the function with different radius values
print_circum(5) # Radius = 5
print_circum(10) # Radius = 10
print_circum(0.45) # Radius = 0.45
OUTPUT
The circumference of a circle with radius 5 is: 31.41593
The circumference of a circle with radius 10 is: 62.83185
The circumference of a circle with radius 0.45 is: 2.82743
Circumference =2×π×r
where:
r = radius of the circle
π (pi) ≈ 3.14159
The function print_circum takes the radius of a circle as an argument, computes the
circumference, and prints it to five decimal places using {circumference: .5f}. The function is
called three times with different radius to demonstrate its functionality. Using the math module
ensures accurate π value calculation, while the formatted output maintains consistency across
different radius values.
PART 2
INPUT
def generate_catalog():
""" Displays a product catalog with individual and combo pricing. Includes discounts for
combo purchases as specified. """
products = {
"Premium Ankara Fabric": 12000.0,
"Gourmet Plantain Chips": 4000.0,
"Dove Luxury Soap Set": 6000.0
}
# Calculate combo discounts
combos = {
"Combo 1 (Fabric + Chips)": (products["Premium Ankara Fabric"] + products["Gourmet
Plantain Chips"]) * 0.9,
"Combo 2 (Chips + Soap)": (products["Gourmet Plantain Chips"] + products["Dove Luxury
Soap Set"]) * 0.9,
"Combo 3 (Fabric + Soap)": (products["Premium Ankara Fabric"] + products["Dove
Luxury Soap Set"]) * 0.9,
"Gift Pack (All Items)": sum(products.values()) * 0.75
}
# Display catalog
print("Output:\nOnline Store\n---")
print("Product(S)\t\tPrice")
for item, price in products.items():
print(f"{item}\t{price}")
for combo, price in combos.items():
print(f"{combo}\t{price}")
print("\nFor delivery Contact: +2348032456321")
generate_catalog()
Output:
Online Store
---
Product(S) Price
Premium Ankara Fabric 12000.0
Gourmet Plantain Chips 4000.0
Dove Luxury Soap Set 6000.0
Combo 1 (Fabric + Chips) 14400.0
Combo 2 (Chips + Soap) 9000.0
Combo 3 (Fabric + Soap) 16200.0
Gift Pack (All Items) 16500.0
The function checks which items are selected (Boolean flags). Discounts are applied based on
the number of items purchased. The output clearly displays the discount applied (if any) and the
final price.
This solution is entirely original and demonstrates fundamental programming concepts like
conditionals, loops, and dictionaries.