私はPythonには新しいので、私の質問は間違っていますが、私には負担してください。だから、基本的には、(x)面のダイスをランダムに生成する確率を計算するプログラムを作っています。問題は、変数 "idealProb"を印刷しようとすると、100%の確率でデバッガに実際の小数点が表示されていない限り0に丸められているように見えます。印刷時のPython四捨五入変数
import random
import sys
import os
import time
clear = lambda: os.system('cls')
clear()
rolls = []
sides = []
x = 1
totalSides = int(input("How many sides do you want this die to have?"))
clear()
numSides = int(input("How many of those sides are you trying to land on?"))
nS = numSides
while numSides >= 1:
clear()
s = int(input("Possibility %i:" %(x)))
sides.append(s)
numSides -= 1
x += 1
idealProb = nS/totalSides
print("Ideal probability: %i" %(idealProb))
P.S.私のコードに関する他のコメント、それほど面倒でない方法や、私がやっていることをやるための簡単な方法についてのアドバイスは、Pythonが私の最初の言語であるので、私はPythonの初心者で一般的なコーディングです。すべての助けをありがとう!
「%i」は、Pythonに整数表現を明示的に指示します。代わりに '%f'のようなものを試してみてください。 –
または理想的な確率:{idealProb} "(これはPython 3.6の新機能です) – Eevee
Pythonの[round()の複製が正しく丸められていないようです](https://stackoverflow.com/questions/56820/round-in-python-does-seem-be-be-rounding-appropriate) –