【发布时间】:2015-04-27 22:00:01
【问题描述】:
我是 Python 新手,我在 Maya 中创建了一个程序,用于创建一个太阳系。这是导致问题的代码的一部分(希望足以理解)。第一个函数定义了行星的半径,然后相应地创建了一个球体。第二个函数需要使用变量 planetRadiusStr 来确定 Torus(ring) 的半径。但是,planetRadiusStr 仅在第一个函数中定义,所以我知道我需要以某种方式在函数之间传递变量。但是,我似乎无法让它发挥作用。有人可以帮忙吗?
def planetRadius():
planetRadiusStr = raw_input("Please enter the radius of the planet:")
if float(planetRadiusStr)<float(sunRadiusStr):
cmds.polySphere(radius=float(planetRadiusStr), n='planet1')
else:
print "Planet Radius must be less than Sun Radius"
planetRadius()
def planetRings():
ringsStr = raw_input("Would you like this planet to have a ring?").lower()
if str(ringsStr) == "yes":
cmds.polyTorus(r=float(planetRadiusStr)*2, sr=0.5, n='ring1')
cmds.scale(1,0.2,1)
elif str(ringsStr) == "no":
pass
else:
print "Please enter 'yes' or 'no'."
planetRings()
(如果更容易阅读,我可以上传我的代码照片。) 谢谢!
【问题讨论】:
标签: python variables argument-passing maya