Programming Assignment Unit 2
Programming Assignment Unit 2
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 circumference.
Call your print_circum function three times with different values for radius.
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 the accuracy of my 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:
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.
As expected, my first attempt failed but not for the reason I thought. It appears that there is a
local variable error which is occurring because the variables combo"" and discount" " are
interdependant. Next, I tried assigning the variable 'discount' to the operation '/10' but had
noluck. After burning my brain, I took the long way and came up with:
I now had the calculations correct but needed to also correct the appearance of the catalog which
I did not pay much attention to when starting the foundation. Here I needed to separate mystrings
with commas.
Now that I fixed the small error, I decided to fill out the rest of the items section of the
function.
Getting on the right track, I then started to tweak the amount of spaces, and complete the
catalog with variables and text.
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. I didn't completely understand why this was happening (likely a PEMDAS mistake) so
instead of using the operand / with integers I decided to use * with floats.
References
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree
Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf
https://www.geeksforgeeks.org/how-to-make-a-table-in-python/