Untitled
unknown
python
4 years ago
1.5 kB
6
Indexable
class Thing:
def __init__(self, name, cost):
self.name=name
self.cost=cost
class Table:
def init(self, max_size=10):
self.max_size=max_size
self.things=[]
def put(self, thing):
if len(self.things) == self.max_size:
raise Exception("Слишком много вещей")
self.things.append(thing)
def get_by_name(self, thing_name):
for th in self.things:
if(th.name==thing_name):
return th
return None
def deleter(self, name):
th=self.get_by_name(name)
self.things.remove(th)
def get_by_cost(self, thing_cost):
for th in self.things:
if(th.cost==thing_cost):
return th
return None
def get_cost_sum(self):
return sum(map(lambda th: th.cost, self.things))
vilka = Thing("Vilka", 1000)
while True:
print("""1. Add
2.Delete
3.Find
4. Sum
5.Exit/Quit""")
ans=input("What would you like to do? ")
if ans=="1":
Table.put(input("Введите название предмета:"))
print("\nAdded")
elif ans=="2":
Table.deleter()
print("\nDeleted")
elif ans=="3":
print("\n Name find - ")
Table.get_by_name(insert())
elif ans=="4":
print("\n Sum = ")
Table.get_cost_sum()
elif ans =="5":
print("Good bye")
elif ans !="":
print("\n Not Valid Choice Try again")Editor is loading...