Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Programming Assignment Unit 2

Uploaded by

htetkaungthaw27
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Programming Assignment Unit 2

Uploaded by

htetkaungthaw27
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Programming Assignment Unit 2

Htet Kaung Thaw


CS 1101 – Programming Fundamentals
Instructor : Safia Hirari
Deadline : 28th November 2024

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.

Before creating a function to calculate the circumference of a circle, we must import


Python's math module. As outlined by Downey (2015), this module provides access to
mathematical constants and functions. By executing the command import math, we can utilize
the value of pi through math.pi within 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 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:

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.

Initially, after reading Part 2, I realized my current function wouldn't be directly


applicable. However, I wanted to create a basic structure to build upon. To do this, I opened two
terminal windows and copied the relevant code from the old to the new environment.

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.

I was please to be resulted with the final output


While brute
forcing/experimenting
this assignment was very
fun, 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”. Are there
functions to create
tables, columns, headers,
rows, etc with base
Python (no imports)? I
would love to see an
example of the most
simplified
function of this catalog.
While brute
forcing/experimenting
this assignment was very
fun, 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”. Are there
functions to create
tables, columns, headers,
rows, etc with base
Python (no imports)? I
would love to see an
example of the most
simplified
function of this catalog.

While brute forcing/experimenting this assignment was very fun, 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". Are there functions to create tables,
columns, headers, rows, etc with base Python (no imports)? I would love to see an example of
the most simplified function of this catalog.

References

Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree
Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf

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