27 Ayush
27 Ayush
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
Screenshot:
B:
import math
def euclidean_distance(x1, y1, x2, y2):
distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return distance
Screenshot:
C:
def calculate_total_cost(item_prices):
return sum(item_prices)
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))
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