CHP 3 Remaining
CHP 3 Remaining
Question # 3.19
In [1]: amount = int(input("Enter the amount deposited: "))
if amount < 5000:
interest_rate = 0.03
elif amount < 10000:
interest_rate = 0.04
elif amount < 20000:
interest_rate = 0.05
else:
interest_rate = 0.06
interest = amount * interest_rate
print("Interest earned for one year: Rs.", interest)
Question # 3.20
In [4]: # ask the user for the item name, previous price, and current price
item_name = input("Enter the item name: ")
previous_price = float(input("Enter the previous price: "))
current_price = float(input("Enter the current price: "))
price_difference = current_price - previous_price
price_change_percent = (price_difference / previous_price) * 100
if price_difference > 0:
print(f"The price of {item_name} has increased by {price_change_percent:.2f
elif price_difference < 0:
print(f"The price of {item_name} has decreased by {price_change_percent:.2f
else:
print(f"The price of {item_name} has not changed.")
In [29]: # ask the user for the item name, previous price, and current price
item_name = input("Enter the item name: ")
previous_price = float(input("Enter the previous price: "))
current_price = float(input("Enter the current price: "))
price_difference = current_price - previous_price
price_change_percent = (price_difference / previous_price) * 100
if price_difference > 0:
print(f"The price of {item_name} has increased by {price_change_percent:.2f
elif price_difference < 0:
print(f"The price of {item_name} has decreased by {price_change_percent:.2f
else:
print(f"The price of {item_name} has not changed.")
Question # 3.21
In [11]: units = int(input("Enter the number of units consumed: "))
# Calculate the electricity charges
if units <= 100:
charges = units * 7.74
elif units <= 200:
charges = 100 * 7.74 + (units - 100) * 10.06
elif units <= 300:
charges = 100 * 7.74 + 100 * 10.06 + (units - 200) * 12.15
elif units <= 700:
charges = 100 * 7.74 + 100 * 10.06 + 100 * 12.15 + (units - 300) * 19.55
else:
charges = 100 * 7.74 + 100 * 10.06 + 100 * 12.15 + 400 * 19.55 + (units - 7
# Print the electricity charges
print("The electricity charges are Rs.",charges)
Question # 3.23
Question # 3.24
In [27]: gain = float(input("Enter the gain amount in Rs.: "))
if gain <= 0:
tax = 0
elif gain <= 5000000:
tax = gain * 0.035
elif gain <= 10000000:
tax = 175000 + (gain - 5000000) * 0.075
elif gain <= 15000000:
tax = 575000 + (gain - 10000000) * 0.1
else:
tax = 1075000 + (gain - 15000000) * 0.15
print("The tax on a gain of Rs.",gain,"is Rs.",tax)
Exercise # 3.25