Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- with open("77777.txt", "a") as f: # open file with write access
- values = [_ for _ in range(1, 8)]
- print(values)
- print(40*"*")
- f.write(40*"*")
- f.write("\n")
- f.write(str(values))
- f.write("\n")
- attempts_list = []
- for test_no in range(0, 10000):
- secret_code = ""
- attempts = 0
- while secret_code != "77777":
- secret_code = ""
- for a in range(0, 5):
- secret_code += str(choice(values))
- # print(secret_code)
- attempts += 1
- print(f"Secret code: {secret_code} , attempt number: {attempts}")
- f.write(f"Secret code: {secret_code} , attempt number: {attempts}")
- f.write("\n")
- attempts_list.append(attempts)
- print(attempts_list)
- max_att = max(attempts_list)
- min_att = min(attempts_list)
- print(max_att)
- print(min_att)
- print(f"Max attempts: {max_att}")
- f.write(f"Max attempts: {max_att}")
- f.write("\n")
- print(f"Min attempts: {min_att}")
- f.write(f"Min attempts: {min_att}")
- f.write("\n")
- avg_att = sum(attempts_list) / len(attempts_list)
- print(f"Avg attempts: {avg_att}")
- f.write(f"Avg attempts: {avg_att}")
- f.write("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement