Program 3.
13:
def collinear(x1, y1, x2, y2, x3, y3):
return (y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1)
x1, y1 = map(int, input("Enter the coordinates of the first point (x1, y1): ").split())
x2, y2 = map(int, input("Enter the coordinates of the second point (x2, y2): ").split())
x3, y3 = map(int, input("Enter the coordinates of the third point (x3, y3): ").split())
if collinear(x1, y1, x2, y2, x3, y3):
print("The points are collinear.")
else:
print("The points are not collinear.")
Program 3.14:
def is_isosceles(a, b, c):
return a == b or b == c or a == c
a = float(input("Enter the length of the first side: "))
b = float(input("Enter the length of the second side: "))
c = float(input("Enter the length of the third side: "))
if is_isosceles(a, b, c):
print("The triangle is isosceles.")
else:
print("The triangle is not isosceles.")
Program 3.15:
import math
def is_right_triangle(a, b, c):
sides = sorted([a, b, c])
return [Link](sides[0] ** 2 + sides[1] ** 2, sides[2] ** 2)
a = float(input("Enter the length of the first side: "))
b = float(input("Enter the length of the second side: "))
c = float(input("Enter the length of the third side: "))
if is_right_triangle(a, b, c):
print("The triangle is a right triangle.")
else:
print("The triangle is not a right triangle.")
Program 3.16:
def package_shipping_charges(weight):
if weight <= 2:
return 200
elif weight <= 6:
return 400
elif weight <= 10:
return 550
else:
return 700
weight = float(input("Enter the weight of the package in kg: "))
charges = package_shipping_charges(weight)
print(f"The shipping charges for a package of {weight} kg is Rs. {charges}.")
Program 3.17:
def magic_date(month, day, year):
return month * day == year % 100
month = int(input("Enter the month (1-12): "))
day = int(input("Enter the day (1-31): "))
year = int(input("Enter the year: "))
if magic_date(month, day, year):
print(f"{month}/{day}/{year} is a magic date.")
else:
print(f"{month}/{day}/{year} is not a magic date.")
Program 3.18:
def calculate_interest(deposit):
if deposit < 5000:
return deposit * 0.03
elif deposit < 10000:
return deposit * 0.04
elif deposit < 20000:
return deposit * 0.05
else:
return deposit * 0.06
deposit = float(input("Enter the amount deposited: Rs. "))
interest = calculate_interest(deposit)
print(f"The interest for Rs. {deposit} deposited is Rs. {interest}.")
Program 3.19:
def price_change_percentage(old_price, new_price):
return ((new_price - old_price) / old_price) * 100
old_price = float(input("Enter the previous price: Rs. "))
new_price = float(input("Enter the current price: Rs. "))
percentage_change = price_change_percentage(old_price, new_price)
if percentage_change > 0:
print(f"The price increased by {percentage_change:.2f}%.")
else:
print(f"The price decreased by {-percentage_change:.2f}%.")
Program 3.20:
def electricity_bill(units):
if units <= 100:
return units * 7.74
elif units <= 200:
return 100 * 7.74 + (units - 100) * 10.06
elif units <= 300:
return 100 * 7.74 + 100 * 10.06 + (units - 200) * 12.15
elif units <= 700:
return 100 * 7.74 + 100 * 10.06 + 100 * 12.15 + (units - 300) * 19.55
else:
return 100 * 7.74 + 100 * 10.06 + 100 * 12.15 + 400 * 19.55 + (units - 700) * 22.65
units = int(input("Enter the number of units consumed: "))
bill = electricity_bill(units)
print(f"Your electricity bill is Rs. {bill:.2f}.")
Program 3.21:
def slab_benefit(units):
if units <= 300:
return electricity_bill(units)
else:
return electricity_bill(300) + (units - 300) * 19.55
units = int(input("Enter the number of units consumed: "))
bill = slab_benefit(units)
print(f"Your electricity bill with slab benefit is Rs. {bill:.2f}.")
Program 3.22:
def income_tax(income):
if income <= 400000:
return 0
elif income <= 600000:
return 0.05 * (income - 400000)
else:
return 0.05 * 200000 + 0.1 * (income - 600000)
income = float(input("Enter the annual income: Rs. "))
tax = income_tax(income)
print(f"The income tax for Rs. {income} is Rs. {tax:.2f}.")