-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ03.py
106 lines (77 loc) · 2.55 KB
/
Q03.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
Aledutron
SPPU 2019 SE DSL Lab
SPPU Computer Engineering Second Year (SE) Data Structure Lab (DSL) / Fundamentals of Data Structures (FDS) Assignments (2019 Pattern)
Youtube DSL / FDS Playlist Link: https://youtube.com/playlist?list=PLlShVH4JA0osUGQB95eJ8h5bTTzJO89vz&si=u12IYwo93Z7RU4e8
Problem Statement:
Group-A\Q03.py
Write a Python program for department library which has N books, write functions for following:
a) Delete the duplicate entries
b) Display books in ascending order based on cost of books
c) Count number of books with cost more than 500.
d) Copy books in a new list which has cost less than 500.
Explaination Video Link: https://www.youtube.com/watch?v=E0OdKqu_J9A&list=PLlShVH4JA0osUGQB95eJ8h5bTTzJO89vz&index=5&pp=iAQB
"""
print(__doc__)
class Book:
def __init__(self, name, cost):
self.name = name
self.cost = cost
book_list = []
def add_book(name, cost):
book = Book(name, cost)
book_list.append(book)
add_book("DSA", 500)
add_book("CG", 400)
add_book("DELD", 300)
add_book("OOP", 700)
add_book("DM", 590)
add_book("DSA", 500)
add_book("DELD", 300)
add_book("OOP", 700)
for book in book_list:
print(book.name, book.cost)
def delete_duplicate(book_list):
does_copy_exists = False
unique_book_list = []
for book in book_list:
for u_book in unique_book_list:
if u_book.name == book.name and u_book.cost == book.cost:
does_copy_exists = True
if not does_copy_exists:
unique_book_list.append(book)
return unique_book_list
book_list = delete_duplicate(book_list)
print("\na.")
for book in book_list:
print(book.name, book.cost)
def arrange_books(book_list):
for j in range(len(book_list) - 1):
min_value_index = j
for i in range(j, len(book_list)):
if book_list[min_value_index].cost > book_list[i].cost:
min_value_index = i
book_list[j], book_list[min_value_index] = (
book_list[min_value_index],
book_list[j],
)
arrange_books(book_list)
print("\nb.")
for book in book_list:
print(book.name, book.cost)
def count_book_filter(cost=500):
cnt = 0
for book in book_list:
if book.cost >= cost:
cnt += 1 # cnt = cnt+1
return cnt
print("\nc.", count_book_filter())
def seperate_book_filter(cost=500):
less_cost_book = []
for book in book_list:
if book.cost < cost:
less_cost_book.append(book)
return less_cost_book
print("\nd.")
for book in seperate_book_filter():
print(book.name, book.cost)