0% found this document useful (0 votes)
30 views4 pages

27 Ayush

The document describes 3 Python programs: 1) A km to miles converter, 2) A program to calculate the Euclidean distance between two points, and 3) A program to generate grocery bills that calculates subtotals, discounts, taxes and the payable amount. Code snippets and sample outputs are provided for each program. The aim was to apply Python concepts like functions, inputs, calculations and formatting outputs.

Uploaded by

sachana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

27 Ayush

The document describes 3 Python programs: 1) A km to miles converter, 2) A program to calculate the Euclidean distance between two points, and 3) A program to generate grocery bills that calculates subtotals, discounts, taxes and the payable amount. Code snippets and sample outputs are provided for each program. The aim was to apply Python concepts like functions, inputs, calculations and formatting outputs.

Uploaded by

sachana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL 1

Name: Ayush Sachan

Section: AIML-B
Aim:
A. Write a python program to convert from Kilometres to
miles
A. Write a python program to calculate Euclidean distance
between two points A (x1, y1) and B (x2, y2)
B. Write a python program to generate bills for a grocery
store. Accept from user: name of item, quantity, cost for three
items. Compute the actual cost payable by applying discount
(in %) and tax (in %). Print the bill in the following format.

***********BILL*************
Item Name Quantity Price
*****************************
Total
*****************************
Discount
Tax
*****************************
Payable amount
Codes:
A:
def km_to_miles(kilometers):
miles = kilometers * 0.621371
return miles

kilometers = float(input("Enter distance in kilometers: "))


miles = km_to_miles(kilometers)
print(f"{kilometers} kilometers is equal to {miles} miles")

Screenshot:

B:
import math
def euclidean_distance(x1, y1, x2, y2):
distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return distance

# Input from the user


x1 = float(input("Enter x-coordinate of point A: "))
y1 = float(input("Enter y-coordinate of point A: "))
x2 = float(input("Enter x-coordinate of point B: "))
y2 = float(input("Enter y-coordinate of point B: "))

distance = euclidean_distance(x1, y1, x2, y2)


print(f"The Euclidean distance between A({x1}, {y1}) and B({x2}, {y2}) is {distance}")

Screenshot:

C:
def calculate_total_cost(item_prices):
return sum(item_prices)

def calculate_discount(total_cost, discount_percent):


return (total_cost * discount_percent) / 100

def calculate_tax(total_cost, tax_percent):


return (total_cost * tax_percent) / 100

items = []
for i in range(3):
item_name = input(f"Enter name of item {i+1}: ")
quan ty = int(input(f"Enter quan ty of {item_name}: "))
cost = float(input(f"Enter cost of {item_name} per item: "))
items.append((item_name, quan ty, cost))

discount_percent = float(input("Enter discount percentage: "))


tax_percent = float(input("Enter tax percentage: "))

item_prices = [quan ty * cost for _, quan ty, cost in items]


total_cost = calculate_total_cost(item_prices)
discount = calculate_discount(total_cost, discount_percent)
tax = calculate_tax(total_cost - discount, tax_percent)
payable_amount = total_cost - discount + tax

print("\n***********BILL*************")
print("Item Name Quan ty Price")
print("*****************************")
for item_name, quan ty, cost in items:
print(f"{item_name:<10} {quan ty:<9} {cost:<6.2f}")
print("*****************************")
print(f"Total {total_cost:<6.2f}")
print(f"Discount ({discount_percent}%) {discount:<6.2f}")
print(f"Tax ({tax_percent}%) {tax:<6.2f}")
print("*****************************")
print(f"Payable amount {payable_amount:<6.2f}")
print("\n***********END**************")

Screenshot:
Conclusion:
The aim of this project was to apply Python programming concepts by crea ng programs for
kilometer-to-mile conversion, Euclidean distance calcula on, and genera ng simplified
grocery store bills, thereby reinforcing our understanding of Python fundamentals

You might also like