0% found this document useful (0 votes)
4 views6 pages

Unit2 Programming Assignment

The document outlines a programming assignment by Camila Rocha Jauregui for CS1101, focusing on creating functions in Python. Part 1 involves calculating the circumference of a circle based on user input, while Part 2 simulates an online store's product catalog with pricing and discount logic. The assignment emphasizes fundamental programming concepts such as function definition, variable assignment, and formatted output.
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)
4 views6 pages

Unit2 Programming Assignment

The document outlines a programming assignment by Camila Rocha Jauregui for CS1101, focusing on creating functions in Python. Part 1 involves calculating the circumference of a circle based on user input, while Part 2 simulates an online store's product catalog with pricing and discount logic. The assignment emphasizes fundamental programming concepts such as function definition, variable assignment, and formatted output.
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

Programming Assignment – Unit 2

Student Name: Camila Rocha Jauregui

Course: CS1101 - Programming Fundamentals

Date: July 7th, 2025

Part 1: Function to Calculate the Circumference of a Circle

# Function to calculate and print the circumference of a circle using user input

def print_circum():

pi = 3.14159

radius = float(input("Enter the radius of the circle: "))

circumference = 2 * pi * radius

print(f"The circumference of a circle with radius {radius} is {circumference:.2f}\n")

# Function calls to allow user to input three different values

print_circum()

print_circum()

print_circum()

Inputs and Outputs Screenshot:


Explanation:

In Part 1, the task involved creating a Python function called print_circum that calculates

and prints the circumference of a circle based on user input. The function first defines the

value of π as 3.14159, then prompts the user to enter the circle’s radius. Using the

mathematical formula 2 πr , the circumference is calculated. The output is formatted to

show two decimal places for clarity and precision. This demonstrates several fundamental

programming concepts, including input handling, variable assignment, arithmetic

operations, and formatted string output. Calling the function multiple times illustrates the

modularity and reusability of functions, which are essential concepts in programming

(Downey, 2015).

Part 2: Company Product Catalog and Discount Function

# Online Store Product Catalog with logic and formatted output

def display_catalog():

print("Output:\n")

print("Online Store")

print("---------------------------")

print("Product(S)\t\tPrice")

# Individual prices

item1 = 200.0

item2 = 400.0

item3 = 600.0
print(f"Item 1\t\t{item1}")

print(f"Item 2\t\t{item2}")

print(f"Item 3\t\t{item3}")

# Combos

combo1 = (item1 + item2) * 0.9

combo2 = (item2 + item3) * 0.9

combo3 = (item1 + item3) * 0.9

combo4 = (item1 + item2 + item3) * 0.75

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{combo4:.1f}")

print("\n___________________________")

print("For delivery Contact:98764678899")

# Call the function to display catalog

display_catalog()
Output Screenshot:

Features:

 Function Definition and Use: Encapsulates the catalog logic inside a function to

promote modularity and reusability (Downey, 2015).

 Variable Assignment: Uses variables to store item prices and computed discounts.

 Arithmetic Expressions: Calculates discounted combo and gift pack prices using

multiplication and addition operations.

 Formatted Output: Uses formatted print() statements to display prices neatly,

including limiting decimal places.

 Simulation of Real-world Logic: Mimics a real-world store catalog with combo

deals and discount logic.

 Readable and Structured Code: Organizes the display clearly using tabs, spacing,

and section dividers for user-friendly output.


Explanation:

Part 2 simulates an online store’s product catalog, incorporating pricing rules and discount

logic. The program defines individual prices for three products and prints them in a

formatted table. It then calculates discounted prices for combos of two items at 10% off,

and a gift pack containing all three items at 25% off. These computations use arithmetic

expressions directly to apply business rules. The program’s output formatting ensures that

the catalog is easy to read and professional-looking. This example highlights how variables,

expressions, and formatted output can be combined to represent real-world scenarios in

code. It also reflects fundamental programming principles such as clear variable use and

output formatting discussed in introductory programming literature (Downey, 2015).

Conclusion

This assignment provided practical experience with defining and invoking functions to

solve realistic problems. Part 1 reinforced concepts of input processing and applying

mathematical formulas within a function, while Part 2 demonstrated implementing business

logic through discount calculations and formatted output. These tasks required managing

variables, arithmetic operations, and string formatting, which are foundational to Python

programming. The work closely aligns with principles and techniques described in Think

Python, emphasizing clean, modular, and readable code design for practical applications

(Downey, 2015).
References

Downey, A. (2015). Think Python: How to think like a computer scientist (2nd ed.). Green

Tree Press. [Link]

You might also like