Uploaded by Peter Anthony

Programming Assignment Unit 2 - Peter Anthony

advertisement
CS 1101-01 - AY2024-T3
Programming Assignment Unit 2
By
Peter Anthony Pepple
14th February 2024
Part 1
Ans:
INPUT:
import math
def print_circum(radius):
“# Calculate the circumference
circumference = 2 * math.pi * radius” (Kuyucu, 2024)
“# Print the result” (Circle Circumference Python, n.d.)
“print(f"The circumference of a circle with radius {radius} is: {circumference:.5f}")”
(Programming Assignment Unit 2, 2023)
# Call print_circum with different radius values
print_circum(5)
print_circum(7.5)
print_circum(17)
SAMPLE CODE AND OUTPUT:
OUTPUT



Input: print_circum(5)
Output: 31.41593
Input: print_circum(7.5)
Output: 47.12389
Input: print_circum(15)
Output: 94.24778
Part 2
TEST CODE:
def calculate_price(item1_price, item2_price, item3_price):
# Prices for individual items
print(f"Item 1: ${item1_price}")
print(f"Item 2: ${item2_price}")
print(f"Item 3: ${item3_price}")
# Prices for combo packs with a 10% discount
“combo1_price = (item1_price + item2_price) * 0.9
combo2_price = (item2_price + item3_price) * 0.9
combo3_price = (item1_price + item3_price) * 0.9” ([Solved] Develop a Catalog for a
Company Assume That This Company Sells - Programming Fundamentals (CS 1101) Studocu, 2023)
print(f"Combo 1(Item 1 + Item 2): ${combo1_price:.2f}")
print(f"Combo 2(Item 2 + Item 3): ${combo2_price:.2f}")
print(f"Combo 3(Item 1 + Item 3): ${combo3_price:.2f}")
# Price for gift pack with all three items and a 25% discount
gift_pack_price = (item1_price + item2_price + item3_price) * 0.75
print(f"Gift Pack(Item 1 + Item 2 + Item 3): ${gift_pack_price:.2f}")
# Example usage:
calculate_price(200.0, 400.0, 600.0)
OUTPUT:
Item 1: $200.0
Item 2: $400.0
Item 3: $600.0
Combo 1(Item 1 + Item 2): $540.00
Combo 2(Item 2 + Item 3): $900.00
Combo 3(Item 1 + Item 3): $720.00
Gift Pack(Item 1 + Item 2 + Item 3): $900.00
SAMPLE CODE AND OUTPUT
CODE ANALYSIS
1. The code for the function that is created: The function calculate_price takes three
arguments: item1_price, item2_price, and item3_price. These represent the prices of
three different items. The function calculates and prints the prices for individual
items, combo packs of two unique items with a 10% discount, and a gift pack
containing all three items with a 25% discount.
2. Output of the code: When the function calculate_price is called with the prices of the
three items (for example, calculate_price(200.0, 400.0, 600.0)), it prints the prices of
the individual items, the combo packs, and the gift pack. The prices of the combo
packs and the gift pack are calculated by applying the respective discounts.
3. A description of what features your function illustrates: This function
demonstrates several features of Python programming:
o
Function definition: The function calculate_price is defined with three
parameters.
o
Print statements: The print function is used to output the prices of the
individual items, combo packs, and the gift pack.
o
String formatting: The f-string formatting is used to insert the calculated
prices into the print statements.
o
Arithmetic operations: The prices of the combo packs and the gift pack are
calculated using basic arithmetic operations (+, *) and the discount rates are
applied.
REFRENCES

Kuyucu, A. K. (2024, January 19). Python Tutorial 13 — Python Functions: Defining
and Calling Functions. Medium. https://levelup.gitconnected.com/python-tutorial-13python-functions-defining-and-calling-functions-a9bec7782761

circle circumference python. (n.d.). Code Ease. Retrieved February 14, 2024, from
https://www.codeease.net/programming/python/circle-circumference-python

Programming Assignment Unit 2. (2023). Studocu; Studocu.
https://www.studocu.com/en-us/document/university-of-the-people/programmingfundamentals/programming-assignment-unit-2/78880275

[Solved] Develop a catalog for a company Assume that this company sells Programming Fundamentals (CS 1101) - Studocu. (2023). Studocu; Studocu.
https://www.studocu.com/en-us/messages/question/2980930/develop-a-catalog-for-acompany-assume-that-this-company-sells-three-different-items-the-seller
Download