Answer:
Step-by-step explanation:
The following Python code creates all of the necessary functions in order to request and validate all of the inputs from the user. Once everything is entered and validated it calculates the total fee and outputs it to the user. Also calls the entire class at the end using a test variable...
class Customer:
library_card = 0
patrons_name = ""
patrons_address = ""
type_of_book = ""
book_title = ""
days_overdue = 0
fee = 0.0
book_list = ['paperback regular', 'paperback best seller', 'magazine', 'hardcover']
def __init__(self):
self.library_card = self.get_library_card()
self.patrons_address = input("Patron's Address: ")
self.book_title = input("Book Title: ")
self.type_of_book = self.get_type_of_book()
self.days_overdue = float(self.get_days_overdue())
self.calculate_total()
print("Your total Fee is: " + str(self.fee))
def get_library_card(self):
library_card = int(input("Enter 4-digit library card number: "))
if (type(library_card) == type(0)) and (len(str(library_card)) == 4):
return library_card
else:
print("Invalid Card number:")
self.get_library_card()
def get_type_of_book(self):
type_of_book = input("Type of Book 1-4: ")
if (int(type_of_book) > 0) and (int(type_of_book) <= 4):
return int(type_of_book)
else:
print("Invalid Type")
self.get_type_of_book()
def get_days_overdue(self):
days_overdue = input("Number of Days Overdue: ")
if int(days_overdue) >= 0:
return days_overdue
else:
print("Invalid number of days")
self.get_days_overdue()
def calculate_total(self):
if self.type_of_book == 1:
self.fee = 0.20 * self.days_overdue
if self.fee > 8:
self.fee = 8
elif self.type_of_book == 2:
self.fee = 0.50 * self.days_overdue
if self.fee > 15:
self.fee = 15
elif self.type_of_book == 3:
self.fee = 0.25 * self.days_overdue
if self.fee > 5:
self.fee = 5
else:
self.fee = 0.30 * self.days_overdue
if self.fee > 23:
self.fee = 23
test = Customer()