0% found this document useful (0 votes)
15 views4 pages

Pyexp 1

The function facilitates the library checkout process by taking user and book details as parameters. It checks book availability in the inventory and provides success or failure feedback to the user, handling potential errors. Concurrency is addressed by allowing multiple users to request checkouts via a while loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Pyexp 1

The function facilitates the library checkout process by taking user and book details as parameters. It checks book availability in the inventory and provides success or failure feedback to the user, handling potential errors. Concurrency is addressed by allowing multiple users to request checkouts via a while loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 1

Student Name: Sagandeep singh UID: 22BCS14568


Branch: CSE Section/Group:711-A
Semester: 4th
Subject Name: Numerical methods and optimization using python
Subject Code: 22CSH-259

Aim: Imagine you are developing a library checkout system and you need to create
a function that facilitate the checkout process. Describe the design and
functionality of this function considering parameters such as user detail and book
title. Discuss how would implement the logic to check the availability in library
inventory accordingly and provide the feedback to user regarding in sucess or
failure of checkout. Additionally address any potential error scenarios such as book
being out of stock or user provide invalid information. how would you ensure that
the function is efficient readable and adherer best practices in python function
design. provide insight to how would you handle the concurrent request in multiple
user environment use following terms
(i) user detail & book title
(ii) book author and publication data
(iii) library location and opening hours

2. Source Code:

print("************* welcome to library **************")


print("******* B1 resource knowledge centre **********")
print("opening hours: 9.00am to 4.30pm")
book_list ={"ranitatt":3, "virsa":1,"punjab":0}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

def inventory():
# book_list={"ranitatt":3, "virsa":1,"punjab":0}
print("books avaliable ")
print(book_list)

book_name= input("enter book name user wants: ")


val=book_list[book_name]
if(val==0):
print("sorry book not avaliable ")
#exit(0)
else:
book_list[book_name]=val-1
print("checkout sucessful ")

def record():
user_info = ["sagan", "ankit", "raman"]
name = input("enter user name: ")
if name in user_info:
inventory()
else:
print("detail mismatched : error USER NOT FOUND ")

i='y'
while i=='y':
record()
print("is their any user in queue: ")
req=input("enter y or n: ")
i=req
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like