我试图通过递增一个变量(t)来运行一个小方程式,但只是每500次打印一次结果。我正在使用计数器函数和余数来指示何时我有一个整数值,然后打印。在此代码中,它不会打印任何内容。如果我将计数器设置为" counter = counter + 5",它将运行并递增x 5,但每次都打印。你能看出什么问题吗?你可以看到我评论了一些我正在尝试的东西。我认为解决方案是这样的,但我无法弄清楚!
t = 0
counter = 0
#mass rocket = 4390
#mass fuel at launch =
mass= 13000
v = 0
a = 0
d = 0
deltat=.001
#gd = gdisplay(x=0, y=0, width=100, height=4000, title='v vs. t', xtitle='t', ytitle='v',foreground=color.black, background=color.white, xmax=70, xmin=0, ymax=4000, ymin=0)
while (t<=65):
t = t + deltat
mass = 13000 - (130*t)
v = v + ((1880*(130*deltat))/(mass))
a = ((1880/(mass))*((130*deltat)/(deltat)))
d = d + ((v*deltat)+((.5)*a*(deltat*deltat)))
#counter += .001
counter = counter + t
#counter%5==0
if counter %5 == 0:
print (counter)
print (t)
print (v)
#print a
print (d)
我试过这个并没有运行。没有错误,它只是没有做任何事情。
t = 0
counter = 0
#mass rocket = 4390
#mass fuel at launch =
mass= 13000
v = 0
a = 0
d = 0
deltat=.001
#gd = gdisplay(x=0, y=0, width=100, height=4000, title='v vs. t', xtitle='t', ytitle='v',foreground=color.black, background=color.white, xmax=70, xmin=0, ymax=4000, ymin=0)
while (t<=65):
t = t + deltat
mass = 13000 - (130*t)
v = v + ((1880*(130*deltat))/(mass))
a = ((1880/(mass))*((130*deltat)/(deltat)))
d = d + ((v*deltat)+((.5)*a*(deltat*deltat)))
#counter = counter + 5.0
if t % 1.0 == 0:
#print (counter)
print (t)
print (v)
print (d)
Jeepers-对不起,我真是太愚蠢了。我厌倦了它,只运行一次:
t = 0
counter = 0
#mass rocket = 4390
#mass fuel at launch =
#mass= 13000
v = 0
a = 0
d = 0
deltat=.001
#gd = gdisplay(x=0, y=0, width=100, height=4000, title='v vs. t', xtitle='t', ytitle='v',foreground=color.black, background=color.white, xmax=70, xmin=0, ymax=4000, ymin=0)
while (t<=65):
t = t + deltat
mass = 13000 - (130*t)
v = v + ((1880*(130*deltat))/(mass))
a = ((1880/(mass))*((130*deltat)/(deltat)))
d = d + ((v*deltat)+((.5)*a*(deltat*deltat)))
#counter += 1
if counter % 500 == 0:
print (counter)
print(t)
print(v)
print(d)
counter += 1
如果我将计数器增加到if语句之上,它会将t增加.5s而不是.001,并递增计数x 500.我很困惑。
t = 0
counter = 0
#mass rocket = 4390
#mass fuel at launch =
#mass= 13000
v = 0
a = 0
d = 0
deltat=.001
#gd = gdisplay(x=0, y=0, width=100, height=4000, title='v vs. t', xtitle='t', ytitle='v',foreground=color.black, background=color.white, xmax=70, xmin=0, ymax=4000, ymin=0)
while (t<=65):
t = t + deltat
mass = 13000 - (130*t)
v = v + ((1880*(130*deltat))/(mass))
a = ((1880/(mass))*((130*deltat)/(deltat)))
d = d + ((v*deltat)+((.5)*a*(deltat*deltat)))
counter += 1
if counter % 500 == 0:
print (counter)
print(t)
print(v)
print(d)
答案 0 :(得分:0)
增量计数器如下:
counter += 1
并像这样打印
if counter % 500 == 0:
print (counter)