我试图确保值tDiscriminant
始终为正。如下所示,它是根据三个随机生成的数字计算得出的。
s = random.uniform(1,100)
sRounded = round(s,1)
v = random.uniform(1,50)
vRounded = round(v,1)
a = random.uniform(1,20)
aRounded = round(a,1)
tDiscriminant = (vRounded*vRounded)-(2*aRounded*sRounded)
tDiscriminantRooted = math.sqrt(tDiscriminant)
如何使
tDiscriminant
为负数,必须再次生成值s
,v
和a
,直到tDiscriminant
为正数? 最佳答案
尝试
import random
tDiscriminant = -1
while tDiscriminant <= 0:
s = random.uniform(1,400)
sRounded = round(s,1)
v = random.uniform(1,50)
vRounded = round(v,1)
a = random.uniform(1,20)
aRounded = round(a,1)
tDiscriminant = (vRounded*vRounded)-(2*aRounded*sRounded)
tDiscriminantRooted = math.sqrt(tDiscriminant)