Skip to content

Instantly share code, notes, and snippets.

@shreezan123
Created October 4, 2018 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shreezan123/c606f5038ee9e379cf22963ccc1dc9c2 to your computer and use it in GitHub Desktop.
Save shreezan123/c606f5038ee9e379cf22963ccc1dc9c2 to your computer and use it in GitHub Desktop.
class Library:
d1 = {}
def __init__(self):
pass
def add_book(self,book):
self.d1[book] = True
def check_out_book(self,book):
if book in self.d1:
del(self.d1[book])
def return_book(self,book):
self.d1[book] = True
def has_book(self,book):
if book in self.d1:
return True
return False
l = Library()
l.add_book("physics")
l.add_book("math")
print l.has_book("physics") #Expected true
print l.has_book("math") #Expected true
l.check_out_book("math")
print l.has_book("math") #Expected false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment