Advertisement
MichalDK

77777

Aug 9th, 2022 (edited)
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. from random import choice
  2.  
  3. with open("77777.txt", "a") as f:  # open file with write access
  4.     values = [_ for _ in range(1, 8)]
  5.     print(values)
  6.     print(40*"*")
  7.     f.write(40*"*")
  8.     f.write("\n")
  9.     f.write(str(values))
  10.     f.write("\n")
  11.     attempts_list = []
  12.     for test_no in range(0, 10000):
  13.         secret_code = ""
  14.         attempts = 0
  15.         while secret_code != "77777":
  16.             secret_code = ""
  17.             for a in range(0, 5):
  18.                 secret_code += str(choice(values))
  19.             # print(secret_code)
  20.             attempts += 1
  21.         print(f"Secret code: {secret_code} , attempt number: {attempts}")
  22.         f.write(f"Secret code: {secret_code} , attempt number: {attempts}")
  23.         f.write("\n")
  24.         attempts_list.append(attempts)
  25.  
  26.     print(attempts_list)
  27.     max_att = max(attempts_list)
  28.     min_att = min(attempts_list)
  29.     print(max_att)
  30.     print(min_att)
  31.     print(f"Max attempts: {max_att}")
  32.     f.write(f"Max attempts: {max_att}")
  33.     f.write("\n")
  34.     print(f"Min attempts: {min_att}")
  35.     f.write(f"Min attempts: {min_att}")
  36.     f.write("\n")
  37.     avg_att = sum(attempts_list) / len(attempts_list)
  38.     print(f"Avg attempts: {avg_att}")
  39.     f.write(f"Avg attempts: {avg_att}")
  40.     f.write("\n")
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement