import random def judge(P,C): i = C - P if i == 1: print("win") return 2 if i == 2: print("lose") return 1 if i == 0: print("One more.") return 0 if i == -1: print("lose") return 1 if i == -2: print("win") return 2 time = 0 hand = {1:"Rock ",2:"Scissors",3:"Paper "} while time < 1: while True: player = int(input("Janken[1:Rock,2:Scissors,3:Paper]:")) if 1 <= player <= 3: break cpu = random.randint(1,3) print("Player[{}] vs CPU[{}]".format(hand[player],hand[cpu])) j = judge(player, cpu) if j == 0: continue with open (r"C:\Users\admin\Desktop\savedata.txt","a") as file: file.write("{},{}\n".format(player,j)) time += 1 count = [0, 0, 0] win = [0, 0, 0] total_win, play = 0, 0 with open (r"C:\Users\admin\Desktop\savedata.txt","r") as file: for x in file: play += 1 x = x.rstrip("\n").split(",") for i in range(3): if x[0] == "{}".format(i + 1): count[i] += 1 if x[1] == "2": win[i] += 1 for i in range(3): if count[i] == 0: print("{}:{}, {}%".format(hand[i + 1], count[i], round(0, 2))) else: print("{}:{}, {}%".format(hand[i + 1], count[i], round((win[i] /count[i])*100, 2))) total_win += win[i] print("ALL :{}, {}%".format(play, round((total_win /play)*100, 2)))