Advertisement
Guest User

Untitled

a guest
Jun 21st, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import random
  2. doors_n = 3 #сколько всего дверей
  3. num = 100000 #количество попыток
  4. change = True #менять ли дверь
  5. open_one = True #открывается ли лишь одна дверь перед предложением смены или же все кроме выбранной и еще одной случайной
  6. interact = False #выбери дверь сам
  7. prin = False #выводить ли дополнительную информацию
  8. def doors_map():
  9. doors = []
  10. bounty = random.randint(0,doors_n-1)
  11. for i in range(doors_n):
  12. if i != bounty:
  13. doors.append(False)
  14. else:
  15. doors.append(True)
  16. return doors
  17. def del_door(a):
  18. for i in range(len(a)):
  19. if i != choice and a[i] != True:
  20. if a.count(False) != 1:
  21. a[i] = 'hui'
  22. if open_one:
  23. break
  24. else:
  25. a[i] = False
  26. break
  27. return a
  28. counter = 0
  29. for i in range(num):
  30. blind = []
  31. for e in range(doors_n):
  32. blind.append('hui')
  33. a = doors_map()
  34. if interact:
  35. choice = input()
  36. else:
  37. choice = random.randint(0,len(a)-1)
  38. blind[choice] = 'CHOICE'
  39. if prin: print(blind)
  40. a = del_door(a)
  41. for e in range(doors_n):
  42. if a[e] == 'hui':
  43. blind[e] = False
  44. blind[choice] = 'CHOICE'
  45. if prin: print(blind)
  46. if change:
  47. blind[choice] = 'hui'
  48. val_list = []
  49. for i in range(len(a)):
  50. if (a[i] == False or a[i] == True) and i != choice:
  51. val_list.append(i)
  52. if interact:
  53. choice = input()
  54. else:
  55. choice = random.choice(val_list)
  56. blind[choice] = 'CHOICE'
  57. if prin: print(blind)
  58. if a[choice] == True:
  59. counter += 1
  60. if prin: print(a,'u win' if choice else 'u lose')
  61.  
  62. print('\n\n\n\n\n\n', 'Winning rate: ', counter/num)
  63.  
  64.  
  65. #for i in range(num):
  66. # temp = random.randint(0,doors_n-1)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement