gpt4 book ai didi

Python 随机 随机

转载 作者:太空宇宙 更新时间:2023-11-03 19:07:32 26 4
gpt4 key购买 nike

我让随机数低于之前的随机数。

 if Airplane==1:
while icounter<4:
ifuelliter=random.randrange(1,152621)
#litter/kilometer
LpK=152620/13500
km=LpK*ifuelliter


ipca=random.randrange(0,50)
ipcb=random.randrange(0,50)
ipcc=random.randrange(0,812)


#3D space distance calculation
idstance= math.sqrt((icba-ipca)**2 + (icbb-ipcb)**2 + (icbc-ipcc)**2)

totaldist=km-idstance

if totaldist>0:
print "You have enoph fuel to get to New York AirPort"
print ifuelliter,LpK,km,ipca,ipcb,ipcc,idstance
icounter=3

if totaldist<=0:

print "You dont have enoph fuel to get to New York AirPort please go to the nearest one or you will die"
print ifuelliter,LpK,km,ipca,ipcb,ipcc,idstance
icounter=icounter+1

“ipca、ipcb、ipcc”是什么意思,我需要它们向下生长而不是变成其他数字。

最佳答案

只需将 randrange 的第二个参数设置为之前的值即可:

import random
a = random.randrange(0,50)
b = random.randrange(0,a)
while b > a:
b = random.randrange(0,a)

顺便说一句,如果代码开头的缩进样式要小心

if Airplane == 1:
while ....

应该是

if Airplane == 1:
while ....

关于Python 随机 随机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14271260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com