TheAceHome

Untitled

May 23rd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. class Goods:
  2. def __init__(self,goods=[]):
  3. self.goods=goods
  4.  
  5.  
  6. def __str__(self):
  7. return str(self.goods)
  8.  
  9. def append(self,data):
  10. self.goods.append(data +"\n")
  11.  
  12. def wrote(self):
  13. f = open(r"C:\Users\nikit\Downloads\asdf.txt", "w")
  14. for i in self.goods:
  15. f.write(i)
  16. f.close()
  17.  
  18. def max_price(self):
  19. cnt=0
  20. l=[]
  21. for i in self.goods:
  22. c=i.split(" ")
  23. if cnt < int(c[3]):
  24. cnt =int(c[3])
  25. l.clear()
  26. l.append(i)
  27. print(l)
  28.  
  29. def all_companies(self):
  30. l=[]
  31. for i in self.goods:
  32. c=i.split(" ")
  33. if c[2] not in l:
  34. l.append(c[2])
  35. print(l)
  36.  
  37. def sum_all_prices(self):
  38. sum=0
  39. for i in self.goods:
  40. c=i.split(" ")
  41. sum+=int(c[3])
  42. print(sum)
  43.  
  44.  
  45. def __iter__(self):
  46. return self
  47.  
  48. def __next__(self):
  49. return self
  50.  
  51.  
  52.  
  53.  
  54. meow=open(r"C:\Users\nikit\Downloads\lrh.txt","r")
  55. texts=meow.readlines()
  56. print(texts[0])
  57. a=Goods(texts)
  58. print(a)
  59. a.append("Клавиатура Math3 Card 70000")
  60. print(a)
  61. meow.close()
  62. a.wrote()
  63. a.max_price()
  64. a.all_companies()
  65. a.sum_all_prices()
  66. a.append("Комп 45667 Apple 4500")
  67. a.all_companies()
Advertisement
Add Comment
Please, Sign In to add comment