Skip to content

Commit 7d66dd7

Browse files
committed
Day9 added
1 parent c5dfc22 commit 7d66dd7

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

Day9/inheritance.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Kurama:
2+
def powers(self):
3+
return "Nine Tails Chakra"
4+
5+
class Naruto(Kurama):
6+
def battle(self):
7+
return "Sage Mode"
8+
def superpowers(self):
9+
return "I will just Talk"
10+
11+
war = Naruto()
12+
print(war.battle())
13+
print(war.powers())
14+
print(war.superpowers())
15+
16+
"""
17+
class SliceOfLife:
18+
def inside(self):
19+
return "Inside Slice of Anime"
20+
21+
class Romance(SliceOfLife):
22+
def inside(self):
23+
return "Inside Romance"
24+
25+
class Comedy(Romance):
26+
def inside(self):
27+
return "Inside Comedy"
28+
29+
genre = Comedy()
30+
print(genre.inside())
31+
genre1 = Romance()
32+
print(genre1.inside())
33+
genre2 = SliceOfLife()
34+
print(genre2.inside())
35+
36+
"""

Day9/library.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from typing import SupportsIndex
2+
import termcolor
3+
class Library:
4+
def __init__(self,book_category):
5+
self.books = book_category
6+
7+
def intro(self):
8+
message = """\n\t****** Welcome To Anime Vyuh Library ******\n 1. List Of Books\n 2. Request A Book\n 3. Return A Book\n 4. Exit"""
9+
print(f"\t{message}")
10+
11+
def listofbooks(self):
12+
print("\t *** Here Are The List Of Book *** ")
13+
for index,book in enumerate(self.books,start=1):
14+
print(f"{index}:{book}")
15+
16+
def returnbook(self,bookname):
17+
if bookname not in self.books:
18+
self.books.append(bookname)
19+
termcolor.cprint("\nThank You For Returning Book Back",color="green")
20+
termcolor.cprint(f"{bookname} book is added",color="blue")
21+
else:
22+
termcolor.cprint("\nBook Exists",color="yellow")
23+
24+
def requestbook(self,bookname):
25+
if bookname in self.books:
26+
self.books.remove(bookname)
27+
termcolor.cprint(f"\n{bookname} book is borrowed",color="blue")
28+
termcolor.cprint("Enjoy Your Read",color="green")
29+
else:
30+
termcolor.cprint("\nSorry We Don't Have Such Book",color="yellow")
31+
32+
class Student:
33+
def __init__(self,id):
34+
self.usn = id
35+
36+
def askuser(self):
37+
ask = int(input("\nEnter Your Choice:"))
38+
return ask
39+
40+
def return_book(self):
41+
request_b = input("\nWhich book could you like to return?")
42+
return request_b
43+
44+
def request_book(self):
45+
borrow = input("\nWhich book could you like to borrow?")
46+
return borrow
47+
48+
if __name__ == '__main__':
49+
scan_id = input("Enter your id:")
50+
student = Student(scan_id)
51+
books = ['Automate Stuff With Python','EcmaJavascript','ProGit','Java Fundamentals','Arduino With C']
52+
library_books = Library(books)
53+
while True:
54+
try:
55+
library_books.intro()
56+
choice = student.askuser()
57+
if choice in range(1,5):
58+
if choice == 1:
59+
library_books.listofbooks()
60+
elif choice == 2:
61+
library_books.requestbook(student.request_book())
62+
elif choice == 3:
63+
library_books.returnbook(student.return_book())
64+
elif choice == 4:
65+
print("\nThank you for visting! \nHappy Reading")
66+
exit()
67+
else:
68+
termcolor.cprint("Enter A Valid Choice between (1-4)",color="red")
69+
except ValueError:
70+
termcolor.cprint("Invalid Choice",color="red")

Day9/oops.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Anime:
2+
def __init__(self,anime_name,anime_episode):
3+
self.name = anime_name
4+
self.episode = anime_episode
5+
6+
def overview(self):
7+
print("Anime Name:",self.name)
8+
print("Its Episode:",self.episode)
9+
10+
anime1 = Anime("Psycho Pass",41) #first instance
11+
anime1.overview()
12+
anime2 = Anime("Vinland Saga",24) #second instance
13+
anime2.overview()
14+
anime3 = Anime("Ergo Proxy",23) #third instance
15+
anime3.overview()
16+
anime4 = Anime() #error, it cant be empty
17+
anime4.overview()

0 commit comments

Comments
 (0)