0% found this document useful (0 votes)
15 views5 pages

CS 1101 Programming Assignment 2

The document outlines a programming assignment that consists of two parts. Part 1 involves a function to calculate and print the circumference of a circle based on its radius, demonstrating the use of the math module and formatted output. Part 2 presents a product catalog function that displays individual and combo pricing with discounts, showcasing efficient data management using dictionaries and encapsulation of logic.

Uploaded by

blessingojuloge
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)
15 views5 pages

CS 1101 Programming Assignment 2

The document outlines a programming assignment that consists of two parts. Part 1 involves a function to calculate and print the circumference of a circle based on its radius, demonstrating the use of the math module and formatted output. Part 2 presents a product catalog function that displays individual and combo pricing with discounts, showcasing efficient data management using dictionaries and encapsulation of logic.

Uploaded by

blessingojuloge
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/ 5

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

The circumference of a circle is calculated using the formula:

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

For delivery Contact: +2348032456321


The products and their prices are stored in a dictionary (products = {…}), demonstrating
efficient key-value pairing for inventory management. This allows O(1) lookup time for prices.
Combo prices are calculated programmatically using sum() and percentage discounts (10% for
pairs, 25% for the gift pack). This avoids hardcoding prices, making the system adaptable to
changes: he output mimics the requested tabular format using \t for alignment and \n for line
breaks. String formatting (f-strings) ensures consistent decimal places. The catalog generation is
encapsulated in a single function (generate catalog()), demonstrating separation of concerns. All
calculations and display logic are self-contained.

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.

You might also like