Library Charges Program in Python


A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days your membership will be cancelled. Write a program to accept the number of days the member is late to return the book and display the fine or the appropriate message.

This program is a simple program that calculates the fine amount for a library based on the number of days a book is overdue. The program takes an input from the user, the number of days the book is overdue and then uses conditional statements to determine the fine amount.

  • The program first checks if the number of days is greater than 0 and less than or equal to 5. If this condition is true, the fine amount is calculated by multiplying 0.50 with the number of days.
  • Next, the program checks if the number of days is greater than or equal to 6 and less than or equal to 10. If this condition is true, the fine amount is calculated by multiplying 1 with the number of days.
  • Then, the program checks if the number of days is greater than 10. If this condition is true, the fine amount is calculated by multiplying 5 with the number of days.
  • If the number of days is greater than 30, then the program will print that the membership would be cancelled.
  • If the input is invalid, the program will print "Invalid" as an output.
  • The program then prints the fine amount that the user needs to pay.

Source Code

days = int(input("Enter the Number of Days :"))
if (days>0 and days<= 5):
	amt = 0.50 * days
	print("Fine Amount Pay to Rs :", amt)
 
elif(days >= 6 and days <= 10):
	amt = 1 * days
	print("Fine Amount Pay to Rs :", amt)
 
elif (days > 10):
	amt = 5 * days
	print("Fine Amount Pay to Rs :", amt)
	if (days > 30):
		print("Your Membership would be Cancelled..")
else:
	print("Invalid")

Output

Enter the Number of Days :23
Fine Amount Pay to Rs : 115


Example Programs