vadimk772336

Untitled

May 5th, 2020
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.66 KB | None | 0 0
  1. def clean(massiv):
  2.   people_list = []
  3.   people_rating = []
  4.   string = ""
  5.   for i in range(len(massiv)):
  6.       flag = 0
  7.       for j in range(len(massiv[i])):
  8.         if ((ord(massiv[i][j]) >= 1040 and ord(massiv[i][j]) <= 1103) and len(string) < 20 and flag < 2):
  9.             string += massiv[i][j]
  10.        
  11.         if (not (ord(massiv[i][j]) >= 1040 and ord(massiv[i][j]) <= 1103) and flag == 1):
  12.             flag = 2;
  13.             if ("+" in massiv[i]):
  14.               index = massiv[i].find("+")
  15.             elif ("−" in massiv[i]):
  16.               index = massiv[i].find("−")
  17.             else:
  18.               index = massiv[i].find("-")
  19.             digit = massiv[i][index-4:index-1]
  20.             people_rating.append(digit)
  21.             people_list.append(string)
  22.             string = ""
  23.             break
  24.            
  25.         elif (not (ord(massiv[i][j]) >= 1040 and ord(massiv[i][j]) <= 1103) and flag == 0 and len(string) > 1):
  26.                 string += massiv[i][j]
  27.                 flag = 1
  28.      
  29.   return (people_list,people_rating)
  30.  
  31. def add_visit(people,people_rating, liga):
  32.   people_visit = [0]*len(people)
  33.   i = 0
  34.   while(i < len(people)):
  35.  
  36.       k = 1
  37.       j = i+1
  38.       while (j < len(people)):
  39.         if (people[i] == people[j]):
  40.           k +=1
  41.           if (people_rating[i] < people_rating[j]):
  42.             people_rating[i] = people_rating[j]
  43.           del people[j], people_rating[j]
  44.           j -= 1
  45.         j +=1
  46.      
  47.       people_visit[i] = k
  48.  
  49.       if (people[i] in liga):
  50.         people[i] += ' (В ЛИГЕ ПРО) '
  51.  
  52.       if ("Оксана" in people[i] or "Алена" in people[i] or "Елена"in people[i] or  "Алла" in people[i] or "Светлана" in people[i]):
  53.             people[i] += ' (женщина)'
  54.       i += 1
  55.   return (people,people_visit,people_rating)
  56.  
  57. def sort_by_visit(massiv):
  58.   for i in range(1,len(massiv)):
  59.     for j in range(1,len(massiv)-i):
  60.         if massiv[j][1] > massiv[j+1][1]:
  61.             massiv[j],massiv[j+1] = massiv[j+1],massiv[j]
  62.   return massiv
  63.  
  64.  
  65. f = open("people.txt")
  66. h = open("liga.txt")
  67.  
  68. people,people_rating = clean(f.readlines())
  69. liga,liga_rating = (clean(h.readlines()))
  70. liga = set(liga)
  71.  
  72.  
  73.  
  74. people,people_visit,people_rating = add_visit(people,people_rating, liga)
  75.  
  76. for i in range(len(people)):
  77.   try:
  78.     people_rating[i] = int(people_rating[i])
  79.   except:
  80.     people_rating[i] = 399
  81.  
  82.  
  83.  
  84. massiv = [[]]
  85. for i in range(len(people)):
  86.   massiv.append([people[i],people_visit[i],people_rating[i]])
  87.  
  88. for i in range(1,len(massiv)):
  89.   if (massiv[i][2] < 290 or massiv[i][2] > 400):
  90.     massiv[i][2] = "delete"
  91.  
  92.  
  93. massiv = sort_by_visit(massiv)
  94.  
  95. for el in massiv:
  96.   print(*el)
  97.  
  98.   Выбор
  99. def fact(x):
  100.   p = 1
  101.   if (x > 0):
  102.     for i in range(1,x+1):
  103.       p *= i
  104.   return p
  105.  
  106. def c(n,k):
  107.   a = fact(n)
  108.   b = fact(k)*fact(n-k)
  109.   return a/b
  110.  
  111. people = 4
  112. us = 2
  113. selected = 2
  114. me = 1
  115.  
  116. combinations_all = c(people,selected)
  117. combinations_0 = c(people-us,selected)
  118. combinations_1 = c(people-us,selected-me)
  119. combinations_2 = c(people-us,selected-us)
  120.  
  121. chance_0 = round(100*combinations_0/combinations_all,2)
  122. chance_1 = round(100*combinations_1/combinations_all,2)
  123. chance_2 = round(100*combinations_2/combinations_all,2)
  124.  
  125.  
  126. print("Не выберут ни одного:", chance_0, '%')
  127. print("Вероятность быть выбранным:", 100*selected/people, '%')
  128. print("Выберут одного и не выберут другого:", chance_1, '%')
  129. print("Выберут двоих:", chance_2, '%')
  130. print("Выберут одного или двоих:", 100-chance_0, '%')
  131.  
  132. print("Проверка: ", chance_1*us+chance_2+chance_0)
Advertisement
Add Comment
Please, Sign In to add comment