Nt1330 Unit 1 Assignment

Words: 495
Pages: 2

CS 1101-01 Programming Fundamentals - AY2024-T4 UNIVERSITY OF THE PEOPLE Programming Assignment Unit 2 Deepika Dhamija (Instructor) Date: 22 April 2024 Programming Assignment Unit 2.

Part 1 For Part 1 of the assignment, I’ve created a function called print_circum that calculates the circumference of a circle given its radius. Here’s the code and the outputs from calling the function with three different radius values: def print_circum(radius): pi = 3.14159 circumference = 2 * pi * radius print(f"The circumference of a circle with radius radius is circumference:.2f")

print_circum(5) # Output: The circumference of a circle with radius 5 is 31.42 print_circum(7) # Output: The circumference of a circle with radius 7 is 43.98 print_circum(10)
…show more content…
I then call this function with three different radius values: 5, 7, and 10. The function prints the calculated circumference for each of these radius values.

In Part 2, I developed a function to calculate the price for a customer based on whether they purchased individual items, a combo pack, or a gift pack. The function applies discounts accordingly. Here’s the function and its output: def calculate_price(items): prices = 'T-shirt': 200.0, 'Sneaker': 400.0, 'Winter Jacket': 600.0 total_price = sum(prices[item] for item in items) discount = 0 total_price = sum(prices[item] for item in items) discount

if len(items) == 2: discount = total_price * 0.10 # 10% discount for two unique items elif len(items) == 3: discount = total_price * 0.25 # 25% discount for a gift
…show more content…
In the second part, I’ve created a function called calculate_price that takes a list of items as an argument. The function calculates the total price of the items, applies a discount based on the number of items, and then prints the total price, discount, and final price. I’ve used a dictionary to store the prices of the items, and I’ve replaced the generic “Item1”, “Item2”, and “Item3” with real products: a T-shirt, a sneaker, and a winter jacket. I then call this function with two different sets of items to demonstrate how the function works.

Reference: Bramel, A. & Co. 2023, August 10 -. Parameters in Tableau vs. Looker. phData. The data is a phData. https://www.phdata.io/blog/parameters-in-tableau-vs-looker/ Downey, A. (2015). The 'Secondary' of the 'Secondary' of the 'Secondary' of the 'Secondary' of the 'Secondary' of the 'Secondary Think Python. How to think like a computer scientist. my.uopeople.edu. Retrieved April 21, 2024, from https://greenteapress.com/thinkpython2/thinkpython2.pdf Team, T. A., & Team, T. A. 2021, March 24. Ecommerce Data analysis for sales strategy using Python. Towards the AI of the world.