Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def clean(massiv):
- people_list = []
- people_rating = []
- string = ""
- for i in range(len(massiv)):
- flag = 0
- for j in range(len(massiv[i])):
- if ((ord(massiv[i][j]) >= 1040 and ord(massiv[i][j]) <= 1103) and len(string) < 20 and flag < 2):
- string += massiv[i][j]
- if (not (ord(massiv[i][j]) >= 1040 and ord(massiv[i][j]) <= 1103) and flag == 1):
- flag = 2;
- if ("+" in massiv[i]):
- index = massiv[i].find("+")
- elif ("−" in massiv[i]):
- index = massiv[i].find("−")
- else:
- index = massiv[i].find("-")
- digit = massiv[i][index-4:index-1]
- people_rating.append(digit)
- people_list.append(string)
- string = ""
- break
- elif (not (ord(massiv[i][j]) >= 1040 and ord(massiv[i][j]) <= 1103) and flag == 0 and len(string) > 1):
- string += massiv[i][j]
- flag = 1
- return (people_list,people_rating)
- def add_visit(people,people_rating, liga):
- people_visit = [0]*len(people)
- i = 0
- while(i < len(people)):
- k = 1
- j = i+1
- while (j < len(people)):
- if (people[i] == people[j]):
- k +=1
- if (people_rating[i] < people_rating[j]):
- people_rating[i] = people_rating[j]
- del people[j], people_rating[j]
- j -= 1
- j +=1
- people_visit[i] = k
- if (people[i] in liga):
- people[i] += ' (В ЛИГЕ ПРО) '
- if ("Оксана" in people[i] or "Алена" in people[i] or "Елена"in people[i] or "Алла" in people[i] or "Светлана" in people[i]):
- people[i] += ' (женщина)'
- i += 1
- return (people,people_visit,people_rating)
- def sort_by_visit(massiv):
- for i in range(1,len(massiv)):
- for j in range(1,len(massiv)-i):
- if massiv[j][1] > massiv[j+1][1]:
- massiv[j],massiv[j+1] = massiv[j+1],massiv[j]
- return massiv
- f = open("people.txt")
- h = open("liga.txt")
- people,people_rating = clean(f.readlines())
- liga,liga_rating = (clean(h.readlines()))
- liga = set(liga)
- people,people_visit,people_rating = add_visit(people,people_rating, liga)
- for i in range(len(people)):
- try:
- people_rating[i] = int(people_rating[i])
- except:
- people_rating[i] = 399
- massiv = [[]]
- for i in range(len(people)):
- massiv.append([people[i],people_visit[i],people_rating[i]])
- for i in range(1,len(massiv)):
- if (massiv[i][2] < 290 or massiv[i][2] > 400):
- massiv[i][2] = "delete"
- massiv = sort_by_visit(massiv)
- for el in massiv:
- print(*el)
- Выбор
- def fact(x):
- p = 1
- if (x > 0):
- for i in range(1,x+1):
- p *= i
- return p
- def c(n,k):
- a = fact(n)
- b = fact(k)*fact(n-k)
- return a/b
- people = 4
- us = 2
- selected = 2
- me = 1
- combinations_all = c(people,selected)
- combinations_0 = c(people-us,selected)
- combinations_1 = c(people-us,selected-me)
- combinations_2 = c(people-us,selected-us)
- chance_0 = round(100*combinations_0/combinations_all,2)
- chance_1 = round(100*combinations_1/combinations_all,2)
- chance_2 = round(100*combinations_2/combinations_all,2)
- print("Не выберут ни одного:", chance_0, '%')
- print("Вероятность быть выбранным:", 100*selected/people, '%')
- print("Выберут одного и не выберут другого:", chance_1, '%')
- print("Выберут двоих:", chance_2, '%')
- print("Выберут одного или двоих:", 100-chance_0, '%')
- print("Проверка: ", chance_1*us+chance_2+chance_0)
Advertisement
Add Comment
Please, Sign In to add comment