Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

# Define a function called print_circum that takes an argument for the circle's radius

def print_circum(radius):
# Import the math module to use the value of pi
import math
# Calculate the circumference using the formula 2 * pi * radius
circumference = 2 * math.pi * radius
# Print the circumference with two decimal places
print(f"The circumference of the circle with radius {radius} is {circumference:.2f}")

# Call the print_circum function three times with different values for radius
print_circum(1) # Input: 1, Output: The circumference of the circle with radius 1 is 6.28
print_circum(5) # Input: 5, Output: The circumference of the circle with radius 5 is 31.42
print_circum(10) # Input: 10, Output: The circumference of the circle with radius 10 is 62.83

# Define a function called online_store that takes no arguments


def online_store():
# Create a dictionary to store the products and prices
products = {
"Item 1": 200.0,
"Item 2": 400.0,
"Item 3": 600.0,
"Combo 1": 540.0, # 10% discount for buying Item 1 and Item 2 together
"Combo 2": 900.0, # 25% discount for buying Item 2 and Item 3 together
"Combo 3": 720.0, # 20% discount for buying Item 1 and Item 3 together
"Combo 4": 900.0, # 50% discount for buying all three items together
}
# Print the products and prices in a table format
print("Online store\n")
print("Product(S)\t\t\tPrice")
for product, price in products.items():
print(f"{product}\t\t\t{price}")
# Print the contact number for delivery
print("\nFor delivery contact: 98764678899")

# Call the online_store function


online_store()

Online store

Product(S) Price
Item 1 200.0
Item 2 400.0
Item 3 600.0
Combo 1 540.0
Combo 2 900.0
Combo 3 720.0
Combo 4 900.0

For delivery contact: 98764678899

The features that this function illustrates are:


.How to use a dictionary to store key-value pairs of data
.How to use a for loop to iterate over the items of a dictionary
.How to use string formatting to print the data in a table format
.How to use comments to explain the logic of the code

You might also like