我正在尝试制作一个程序来模拟运动。这是代码
class Object:
forc={}
srtpos = 0
vel = 0
def __init__(self,mass, srtpos = 0):
self.mass = mass
self.srtpos = 0
def UpVel(vel, time = 1, a = 0):
vel1 = vel + a*t
vel = vel1
def Move(self, vel, time = 1, a = 0):
self.srtpos+= self.vel*time +(0.5)*a*(time**2)
UpVel(self.vel, time, a)
a = Object(5)
print(a.srtpos)
for i in range(5):
a.Move(5)
print(a.srtpos)
该UpVel()
功能正在更新速度。当我尝试通过该Move()
函数运行它时,程序给了我错误
Traceback (most recent call last):
File "/media/atharva/DATA/Python/PhySim.py", line 17, in <module>
a.Move(5)
File "/media/atharva/DATA/Python/PhySim.py", line 13, in Move
UpVel(self.vel, time, a)
NameError: name 'UpVel' is not defined
我已经尝试将函数调用放入__main__
并更改函数的名称。
任何帮助表示赞赏。提前致谢。