Print Circum Function
Print Circum Function
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
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:
b. If a customer purchases a combo pack with two unique items, he gets a 10% 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/
https://www.geeksforgeeks.org/how-to-make-a-table-in-python/