Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
 class Library:
    def __init__(self, listofbooks):
        self.books = listofbooks

    def borrowBook(self, BookName):
        if BookName in self.books:
            self.books.remove(BookName)
            print('Book Issued! ')
        else:
            print('Book Not Available Or Already Issued')
    def displayBooks(self):
        print(f'The Books Available : ')
        for book in self.books:
            print('* '+ book)

    def returnbook(self,BookName):
        self.books.append(BookName)
        print('Book Returned/Added Succesfully')

class Student:

    def requestBook(self):
        self.book = input("Enter the name of the book you want to borrow: ")
        return self.book

    def returnBook(self):
        self.book = input("Enter the name of the book you want to return: ")
        return self.book
         


if __name__=="__main__":
    centraLibrary = Library(["Algorithms", "Django", "Clrs", "Python Notes"])
    student = Student()
                    # centraLibrary.displayAvailableBooks()
    while(True):
        welcomeMsg = '''\n ====== Welcome to Central Library ======
        Please choose an option:
        1. List all the books
        2. Request a book
        3. Add/Return a book
        4. Exit the Library
        '''
        print(welcomeMsg)
        a = int(input("Enter a choice: "))
        if a == 1:
            centraLibrary.displayBooks()
        elif a == 2:
            centraLibrary.borrowBook(student.requestBook())
        elif a == 3:
            centraLibrary.returnBook(student.returnBook())
        elif a == 4:
            print("Thanks for choosing Central Library. Have a great day ahead!")
            exit()
        else:
            print("Invalid Choice!")


What I have tried:

I have a normal dictonary system but it goes off after the program exit this login system must have a create an account system
Posted
Updated 19-Nov-22 22:29pm
Comments
Richard MacCutchan 20-Jan-22 7:37am    
You need some form of permanent storage: flat files (text) or database (SQLite).

class Library:
    def __init__(self, listofbooks):
        self.books = listofbooks

    def borrowBook(self, BookName):
        if BookName in self.books:
            self.books.remove(BookName)
            print('Book Issued! ')
        else:
            print('Book Not Available Or Already Issued')
    def displayBooks(self):
        print(f'The Books Available : ')
        for book in self.books:
            print('* '+ book)

    def returnbook(self,BookName):
        self.books.append(BookName)
        print('Book Returned/Added Succesfully')

class Student:

    def requestBook(self):
        self.book = input("Enter the name of the book you want to borrow: ")
        return self.book

    def returnBook(self):
        self.book = input("Enter the name of the book you want to return: ")
        return self.book
         


if __name__=="__main__":
    centraLibrary = Library(["Algorithms", "Django", "Clrs", "Python Notes"])
    student = Student()
                    # centraLibrary.displayAvailableBooks()
    while(True):
        welcomeMsg = '''\n ====== Welcome to Central Library ======
        Please choose an option:
        1. List all the books
        2. Request a book
        3. Add/Return a book
        4. Exit the Library
        '''
        print(welcomeMsg)
        a = int(input("Enter a choice: "))
        if a == 1:
            centraLibrary.displayBooks()
        elif a == 2:
            centraLibrary.borrowBook(student.requestBook())
        elif a == 3:
            centraLibrary.returnBook(student.returnBook())
        elif a == 4:
            print("Thanks for choosing Central Library. Have a great day ahead!")
            exit()
        else:
            print("Invalid Choice!")
 
Share this answer
 
import requests


class SmsActivate:
    def __init__(self, api_key):
        self.api_key = api_key

    def __request(self, params):
        request_params = {'api_key': self.api_key}
        for _key, _value in params.items():
            if _value != '':
                request_params[_key] = _value
        try:
            return requests.get('https://sms-activate.ru/stubs/handler_api.php', request_params)
        except(ConnectionError, TimeoutError):
            return 'NO_CONNECTION'

    def get_balance(self):
        return self.request({'action': 'getBalance'}).text.split(':')[1]

    def get_balance_and_cashback(self):
        return self.request({'action': 'getBalanceAndCashBack'}).text.split(':')[1]

    def get_numbers_status(self, country='', operator=''):
        return self.request({'action': 'getNumbersStatus', 'country': country, 'operator': operator}).json()

    def get_number(self, service: str, country='', forward='', operator='', ref='', phone_exception=''):
        return self.request({'action': 'getNumber', 'service': service, 'forward': forward, 'operator': operator,
                             'ref': ref, 'country': country, 'phoneException': phone_exception}).text.split(':')[1:]

    def get_m_service_number(self, m_service: str, country='', m_forward='', operator='', ref='', exception=''):
        """m_service = "service1,service2,service3" """
        return self.request({'action': 'getMultiServiceNumber', 'multiService': m_service, 'multiForward': m_forward,
                             'operator': operator, 'ref': ref, 'country': country, 'phoneException': exception}).json()

    def set_status(self, status, number_id, forward=''):
        return self.request({'action': 'setStatus', 'status': status, 'id': number_id, 'forward': forward}).text

    def get_status(self, phone_id):
        return self.request({'action': 'getStatus', 'id': phone_id}).text

    def get_full_sms(self, phone_id):
        return self.request({'action': 'getFullSms', 'id': phone_id}).text

    def get_prices(self, service='', country=''):
        return self.request({'action': 'getPrices', 'service': service, 'country': country}).text

    def get_countries(self):
        return self.request({'action': 'getCountries'}).json()

    def get_qiwi_requisites(self):
        return self.request({'action': 'getQiwiRequisites'}).json()

    def get_additional_service(self, service, parent_id):
        return self.request({'action': 'getAdditionalService', 'service': service, 'id': parent_id}).text.split(':')

    def get_rent_services_and_countries(self, time='', operator='', country=''):
        return self.request({'action': 'getRentServicesAndCountries', 'time': time, 'operator': operator,
                             'country': country}).json()

    def get_rent_number(self, service, time='', operator='', country='', url=''):
        return self.request({'action': 'getRentNumber', 'service': service, 'time': time, 'operator': operator,
                             'country': country, 'url': url}).json()

    def get_rent_status(self, number_id):
        return self.request({'action': 'getRentStatus', 'id': number_id}).json()

    def set_rent_status(self, number_id, status):
        return self.request({'action': 'setRentStatus', 'id': number_id, 'status': status}).json()

    def get_rent_list(self):
        return self.request({'action': 'getRentList'}).json()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900