-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro1.py
110 lines (82 loc) · 2.26 KB
/
pro1.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
107
108
109
110
import os
import sys
import new
def menu():
# return None
j = []
with open("test.log","r") as f:
s = f.read()
j.append(s)
print(s.strip('\n'))
def sear(lys,ele):
# search #
for i in range(len(lys)):
if lys[i] == ele:
# with open()
s = 'Book Found'
inp = input("Type 'yes' to view content: ")
if inp == 'yes':
with open(ele,"r")as f:
det = f.read()
print(det.strip('\n'))
elif inp == 'no':
print("thanks")
else:
print("Wrong Input")
return s+' = '+ lys[i]
return "Not Found"
# def delete():
def exit():
return "Thanks"
if __name__ == "__main__":
c = int(input("""
Choose menu:
1- Write book.
2- View log of book's.
3- Search the book.
4- Delete book.
5- Exit.\n"""))
if c==1:
print("write a book")
c = input("Enter 'yes' to write: ")
y = 'yes'
n = 'no'
if c == y:
# print("test succ")
auth = input("Name of author: ")
bok = input("enter the name of your book: ")
data = new.book(bok,auth)
d = []
d.append(bok)
d.append(auth)
with open("check.txt","a")as f:
for i in d:
f.write(str(i)+'\n')
# print("done = ",d)
print(data)
elif c == n:
print("ok")
else:
print("Error")
elif c==2:
menu()
elif c == 3:
ele = input("search book by Name = ")
"""search function using binary search Algo."""
with open('check.txt','r') as f:
s = f.readlines()
lys = []
for i in range(len(s)):
lys.append(s[i].strip('\n'))
print(sear(tuple(lys),ele))
elif c == 4:
dd = input("do want to delete: ")
if dd == 'yes':
sd = input("enter the name of book: ")
new.dele(sd)
elif dd == 'no':
print("ok")
else:
print("!! wrong input !!")
else:
print(exit())