Question

In: Computer Science

Design a Python example that includes the following Basic concepts: Loops Conditional statements two of the...

Design a Python example that includes the following

Basic concepts:

  • Loops
  • Conditional statements

two of the advanced concepts: Encryption / Decryption, Lists / Dictionaries

Please leave a Description of the program

Solutions

Expert Solution

class library:
    books={1:"The fault in our stars",2:"The Alchemist",3:"The jungle book",4:"Rd sharma",5:"Science everyday",6:"gulliver's travel",7:"Kissing booth",8:"The power of subconsious mind"}
    lend={1:"khushi dubey"}
    avail={2:"The Alchemist",3:"The jungle book",4:"Rd sharma",5:"Science everyday",6:"gulliver's travel",7:"Kissing booth",8:"The power of subconsious mind"}
    def disp(cls):
        for item,var in cls.books.items():
            print(item,var)
        print("\n")    
    def addbook(cls,key,name):
        v=0
        for items in cls.books:
            if key==items:
                print("Book cannot be added.Change the key value\n")
                v=1
        if  v==0:
            cls.books.update({key:name})
            print("Book added to the library\n")   
        print("\n")
    def lend_book(cls,book_no,person):
        count=0
        i=0
        for item,var in cls.lend.items():
            if var==person:
                count=count+1
            elif item==book_no:
                i=1
        if count>=2:
            print("You cannot lend more than two books.Limit over!\n")
        elif i==1:
            print("This book is already lended.Choose some other book\n")
        else:
            cls.lend.update({book_no:person})
            for item,var in cls.books.items():
                if book_no!=item:
                     x=cls.books.get(item)
                     cls.avail.update({item:x})
        for (key) in set(cls.avail) & set(cls.lend):
             del cls.avail[key]
        print("\n")     
    def return_book(cls,book_no,person):
        a=0
        for item in list(cls.lend.keys()):
            if item==book_no:
                del cls.lend[item]
                print("Book returned\n")
                a=1
        if a==1:
            for item,var in cls.books.items():
                    if book_no==item:
                        x=cls.books.get(item)
                        cls.avail.update({item:x})
        else:
            print("book already returned\n")
    def availi(cls):
        print("Books available are:\n")
        for item,var in cls.avail.items():
            print(item,var)

if __name__=='__main__':
    b=library()
    print("Welcome to online library\n")
    while True:
        user_input=int(input("choose 1 to display the books\n2 to add a book\n3 to lend a book according to the availability\n4 to return the book\n"))
        if user_input==1:
            b.disp()
        elif user_input==2:
            book_id=int(input("enter book_id\n"))
            book_name=input("enter book name\n")
            b.addbook(book_id,book_name)
        elif user_input==3:
            b.availi()
            name=input("Enter your name\n")
            book_no=int(input("Enter book_id from the available books above\n"))
            b.lend_book(book_no,name)
        elif user_input==4:
            name=input("Enter your name\n")
            book_no=int(input("Enter book_id you have to return\n"))
            b.return_book(book_no,name)
        else:
            print("wrong input\n")

THIS IS A PROGRAM FOR A LIBRARY SYSTEM.ONE CAN ADD, DISPLAY,LEND AND RETURN A BOOK .ONE PERSON CANNOT LEND MORE THAN 2 BOOKS.HERE FOR LOOP, DICTIONARY AND CONDITIONAL STATEMENTS ARE USED.


Related Solutions

Goals: Concepts related to conditional statements in Python. This is a Python program. You DON’T need...
Goals: Concepts related to conditional statements in Python. This is a Python program. You DON’T need loops for this. Below is the programming task. An employee is paid at a rate of $17.25 per hour for up to 40 regular hours worked in a week. If the employee works more than 40 hours, it is considered overtime. Any hours over 40 hours but less than or equal to 60 are paid at the overtime rate ($12.34 per hour). Any hours...
a summary explaining the basic understanding of the following programming concepts using a language of python:...
a summary explaining the basic understanding of the following programming concepts using a language of python: •Variables •Arithmetic and Logical operations •Sequential coding (Structured programming •Decision structure (If statements) •Repetition structure •Functions with some coding demos inside visual studio code python IDE which can be sent as screenshot. preferably a typed summary please which can be written into powerpoint pleaseeeee ???
ON PYTHON Exercise 4. Insert one or more conditional statements at the end of the source...
ON PYTHON Exercise 4. Insert one or more conditional statements at the end of the source code listed in exercise4.py that prints the messages ‘You entered a negative number’, ‘You entered a zero’, or ‘You entered a positive number’ based on the value entered by the user. value = int( input( 'Enter the value: ') ) # insert the additional statement(s) here Exercise 5. Insert one or more conditional statements at the end of the source code listed in exercise5.py...
Give a brief written summary that includes the basic design and function of a detoxifying or...
Give a brief written summary that includes the basic design and function of a detoxifying or ionizing footbath, typical procedures for how it is used, marketing claim(s), and an example of peudoscience babble (scientific language that is poorly organized, organized for coufusion, or just plain wrong) in the form of an exact quote.
The Conceptual Framework for the Preparation of Financial Statements describes the basic concepts that underlie the...
The Conceptual Framework for the Preparation of Financial Statements describes the basic concepts that underlie the preparation of financial statements for presentation to external users who include shareholders. The contents of The Conceptual Framework serve as a guide to development of International Financial Reporting Standards (IFRSs). It seeks to share understanding of certain key terms that are used in IFRSs and may be referred to by directors when handling a business matter that is not directly addressed by any issued...
Research Design: The basic research design is correlational, that is, two sets of measurements are obtained...
Research Design: The basic research design is correlational, that is, two sets of measurements are obtained from clients who appear at the clinic stating that they desire assistance from their staff to quit smoking. One measurement is the self-report of the current average number of cigarettes (or the equivalent) smoked per day, and the other measure is data from a checklist of anxiety-linked behaviors reportedly experienced during the past 30 days. These two measures will be recorded in an Excel...
Define two out of the following three cost concepts, provide an example for each of your...
Define two out of the following three cost concepts, provide an example for each of your chosen cost concepts, and discuss if and how they are utilised in decision-making by managers: a) Opportunity cost b) Differential cost c) Sunk cost
Which of the following statements is not a required part of the basic financial statements of...
Which of the following statements is not a required part of the basic financial statements of Carlton City? Question 25 options: Government-wide statement of net position. Statement of revenues, expenditures, and changes in fund balances for all governmental funds. Statement of revenues, expenses, and changes in net assets for all fiduciary funds. Statement of cash flows for all proprietary funds.
Drawing on economic concepts and illustrative examples in your answers, discuss the following two statements separately...
Drawing on economic concepts and illustrative examples in your answers, discuss the following two statements separately and whether you agree with the statement or not. 1. A person can benefit from having health insurance coverage even if the premium paid exceeds the cost of health care received. 2. Preserving the concept of consumer sovereignty is sufficient justification for addressing moral hazard using demand-side solutions. To what extent do you agree with this statement in the context of health care?
Cost of quality includes all of the following EXCEPT: Cost of the design and planning of...
Cost of quality includes all of the following EXCEPT: Cost of the design and planning of a quality control program. Cost of the direct appraisal and evaluation of quality in the plant and the field. Cost related to the failure of the product or service discovered by the performing organization while the item(s) is still within its control, or discovered by the customer Cost of operating computers required for the project.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT