猜数字游戏的准确率如何计算?

问题描述 投票:0回答:1

我不知道如何正确计算我需要的尝试次数与在此尝试次数内找到该数字的概率之间关系的准确性。例如。如果我需要 1 次尝试,准确度分数应该是 100%,但如果尝试更多次,准确度分数就会降低。

我的尝试是将尝试次数除以可能的最高选项,然后乘以 100,得到 1 到 100 的准确度分数。

import random

input("You have to guess a number between two others you define! To play, press enter")
play = "yes"

lowest = 1

while play == "yes":
    numIsSet = False

    while not numIsSet:
        highest = int(input("What should the highest number be? "))
        if highest <= lowest:
            print("Highest number should be greater than 1!")
        else:
            numIsSet = True
    numSearch = random.randint(lowest, highest)
    chance = lowest / highest * 100
    numGuess = None
    triesCount = 0

    while numGuess != numSearch:
        numGuess = int(input("Guess a number between " + str(lowest) + " and " + str(highest) + "! "))
        triesCount += 1
        if numGuess == numSearch:
            accuracy = (triesCount / highest) * 100
            print("Cool! You found the correct number with " + str(triesCount) + " tries!")
            print("There was a chance of " + str(chance) + "% to find the correct number at the first try.")
            print("Your accuracy score is:", accuracy)
            if accuracy > 89:
                print("★★★★★   Your score is VERY good!")
            elif accuracy > 70:
                print("★★★★☆   Your score is good!")
            elif accuracy > 50:
                print("★★★☆☆   Your score is ok!")
            elif accuracy > 30:
                print("★★☆☆☆   Your score isn't that good. You can do it better!")
            else:
                print("★☆☆☆☆   Your score is bad. You can do it a lot better!")
            triesCount = 0
            play = input("Do you want to play again? If yes, type 'yes', if not press enter to close the program! ")
            print()
        elif numGuess < lowest or numGuess > highest:
            print("Please use numbers in the given range!")
        elif numGuess < numSearch:
            print("↑  The searched number is HIGHER than yours!")
        else:
            print("↓  The searched number is LOWER than yours!")```
python random formula calculation
1个回答
0
投票

我的方法是 100 - ((100/(最高 - 最低)+1))(triescount)) 例如,尝试次数= 3,最高= 20,最低= 1,100/20 = 5,53 = 15,100 - 15 = 85,因此85%的准确度

这可能是实现准确性的最简单方法

© www.soinside.com 2019 - 2024. All rights reserved.