0% found this document useful (0 votes)
20 views5 pages

Areas Is PI

Uploaded by

yvonnejoseph444
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)
20 views5 pages

Areas Is PI

Uploaded by

yvonnejoseph444
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/ 5

Areas is PI * r * r

Circumference is 2 * PI * r

Python program to calculate the areas and circumference, code to measure area of a circle in python,
python code to compute areas of a circle;

We can code.

Def main () :

Import math

Radii-list= [6, 8.5 ,9)

For radii in radii –list:

Circumference = radii * 2 * math. pi

Area = (radii ^ 2) *math. pi

>>> pi = 3.14159

Pie change in python into pi

>>> print (n)

>>> float (‘3.14159’)

3.14159

>>> str (3.14159)

‘3.14159’

>>> print (math pi)

The circumference of a circle is calculated by 2 pi, where pi =3.14159 (rounded to 5 decimals places).
Write a function called print- circum that takes an argument for the circle radius and print the circles.

The code for your print –circumference function.

First import the math module to access the value of pi. We define the print-circumference function that
takes the radius as an argument. Inside the function, we calculate the circumference using the formula 2
* pi and the store it in the circumference variable.

def. main ():

import math

print –circumference (radius)

circumference= 2 *math pi * radius

math pi=3.14159
console .log (“The circumference of a circle with radius” + radius +” radius+ circumference”),

> |code >

<|p>

Print – circumference function

Print - circumference (6)

Print -_circumference (8.5)

Print _ circumference (9)

Print-circumference (6);

Input: 6

Output: The circumference of a circle with radius 6

37.69908

Print – circumference (8.5)

Input: 8.5

Output: The circumference of a circle with radius 8.5 is

53.40703

Print – circumference (9)

Input: 9

Output: The circumference of a circle with radius 9 is

56.54862

The first the function of the circle using the formula 2 pi r, where pi is approximated to 3.14159. We
then print out with the result using console.log ().

Using the formula 2 * pi * r, which is roughly equal to 3.14159 the first compute the circle’s
circumference with the print – circumference function. The output is then printed using console .log

The circumference of a circle with a radius of 6 is

37.69907999999999

Or

37.69908

When rounded to 5 decimal places according to the output of the print – circumference function when a
radius of 6 is specified.
Develop a catalog for a company.

def. – init –(self)

self. items = {

“item 1 “: 10,

“item 2 “: 20,

“item 3 “: 30,

def. get – price (self, item)

return self. item [item]

def. get – discount – price ( self , item ) :


If Len (items) == 1 :
return self . get – price (items [0] )
elif Len (item ) ==2 :
price =sum ( 20 )
return price *0.9
elif Len ( elif 0.9 (30 ) = = 3
price = sum ( [ self . get – price (item) for item in items])
return price * 0.75

catalog = catalog ( )

print (10)

Print (catalog. get – price (“item 1 “))


# output: 10

Print (catalog. get – discounted – price ([ “item 1 “, “item 2 “]))


# output: 27.0

Print (catalog. get – discounted – price ([ “10 “, “20 “, “30 “,]))


# output: 45.0

Get – price method returns the price of a single item, while the get – discounted – price method
calculates the discounted price based on the number of items purchased.

If the customer purchases a single item, the get – discounted – price method returns the regular price of
that item. If the customer purchase two items, the method calculates the total price of the items and
applies a 10% discount. If the customer purchases all three items, the method applies a 25% discount.

Total cost of a customer’s purchase based


Function calculate total cost ( 10, 20 , 30 )(
total cost =0
combo discount = 10%
gift discount =25%

// total cost + = 10 + 20 + 30

If ((10 > 0 && 20 > 0 && 30 = == 0) // (10 > 0 && 30 > 0 && 20 = = = 0) // (20 > 0 && 30 >0 && 10 = = =
0))

# check if the customer is purchasing a giftpack.


If (item 1 > 0 &&, item 2 >0 && item 3>0) [gift Discount = (total coat *25)/100
]

# Apply the discount to the total cost


total cost - = combo Discount
total cost - = gift Discount

Return total cost;


]

The function takes three parameters, which represent the quality of each item being purchased. it first
calculations the total cost of the individual items. Then it checks if the customer is purchasing a combo
pack or a gift pack, or a gift pack and applies the appropriate discount to the total cost. It returns the
total after all discounts have been applied.

REFERENCE Downey :A (2015).think python :How to think like a computer scientist;

You might also like