【发布时间】:2013-03-23 21:34:51
【问题描述】:
我有点卡住了。
我正在尝试计算移动不同尺寸齿轮的距离,以使它们彼此对齐。我认为它是某种递归调用,但我不知道如何编写它。 我有一个按齿轮顺序排列的半径列表
radiusList=[6,16,14,20,24,28]
所以一档 = 移动距离 = 0
二档移动距离 = 0 + 6 + 16
三档=0 +6 + 16 +16 + 14
第 4 档 = 0 +6 + 16 + 16 + 14 + 14 + 20
5 档 = 0 +6 + 16 + 16 + 14 + 14 + 20, +20 ,+ 24
6 档 = 0 +6 + 16 + 16 + 14 + 14 + 20、+20 、+ 24 + 24 +28 等...
另一件事是我需要更新它——现在对半径大小和齿轮数量很重要。但是我不知道如何处理它。
任何帮助将不胜感激。谢谢你。
更新:谢谢大家,我最后写了这样的东西。不过看起来有点啰嗦。
def createmovesequence():
if numberofcogs == 0 :
void
if numberofcogs == 1:
newmovelist.append(0)
if numberofcogs == 2:
newmovelist.append(0)
newmovelist.append(radiusList[0])
newmovelist.append(radiusList[1])
if numberofcogs >= 3:
newmovelist.append(0)
newmovelist.append(radiusList[0])
#newmovelist.append(radiusList[1])
for i in range(2, len(radiusList)):
newmovelist.append(radiusList[i-1])
newmovelist.append(radiusList[i-1])
newmovelist.append(radiusList[-1])
# elif numberofcogs != len(radiusList):
# 打印'错误'
打印新移动列表
createmovesequence()
我唯一的另一个想法是类似于带有大量 if 语句的 for 循环...
【问题讨论】: