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

Print Circum Function

The document outlines the creation of a Python function to calculate and print the circumference of a circle using the math module. It also describes a project to develop a catalog for a company selling items with specific discount rules for individual purchases, combos, and gift packs. The author discusses challenges faced in implementing the function and references resources for further guidance.

Uploaded by

cisse
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)
27 views6 pages

Print Circum Function

The document outlines the creation of a Python function to calculate and print the circumference of a circle using the math module. It also describes a project to develop a catalog for a company selling items with specific discount rules for individual purchases, combos, and gift packs. The author discusses challenges faced in implementing the function and references resources for further guidance.

Uploaded by

cisse
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/ 6

|49868870

Part 1

The circumference of a circle is calculated by 2πr, where π = 3.14159 (rounded to five decimal

places). Write a function called print_circum that takes an argument for the circle’s radius and

prints the circle's radius. Call your print_circum function three times with different values for

radius.

Before attempting to create a function that finds the circumference of a circle, we first

need to import the Python math module as outlined by Downey. (2015) Running the command

import math nets us with the math library where we can now use “math.pi” to use pi in our

function.

Next, we need to create the function to find and print the circumference of a circle with

whichever radius we use as the argument for the parameter.

The above image is what I came up with to meet the requirements of the function. I intentionally

used the math module to ensure accuracy of answers. Three calls are shown below:
Part 2

Welcome to your first project. Develop a catalog for a company. Assume that this company sells

three different Items. The seller can sell individual items or a combination of any two items. A

gift pack is a special combination that contains all three items. Here are some special

considerations:

a. If a customer purchases individual items, he does not receive any discount.

b. If a customer purchases a combo pack with two unique items, he gets a 10% discount.

c. If the customer purchases a gift pack, he gets a 25% discount.

Write a function for the above scenario. Perform the calculations in code wherever applicable.

The function should be your own creation, not copied from any other source.
|49868870

Now that I fixed that small error, I decided to fill out the rest of the items section of the function.
With a few visual inconsistencies and a rather embarrassing math mistake made for the discount,

I went back to fix them and noticed that “combo4total” was returning 48 instead of 300.

While brute forcing/experimenting, besides DataFrames, which I researched for help with

this catalog, I simply don’t see any other way to simplify this function even further. The best I

can think of is creating one long print function and maybe a few tweaks with the new line

operation “\n”.
|49868870

References

Downey M. (2015). Think Python - How to Think Like a Computer Scientist. Green Tea Press.

https://greenteapress.com/wp/think-python-2e/

Examples of the tables I was referring to

Geeksforgeeks. (February 22, 2023). How to make a table in Python? Geeksforgeeks.

https://www.geeksforgeeks.org/how-to-make-a-table-in-python/

You might also like