1
0

add print method to Body object

This commit is contained in:
Thibault Barnouin
2021-10-22 11:25:14 +02:00
parent b452bee164
commit f10f23bdbc
2 changed files with 32 additions and 29 deletions

17
lib/class.py Normal file → Executable file
View File

@@ -1,20 +1,25 @@
import numpy as np
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
Class definition for physical atribute
"""
import numpy as np
class Body:
def __init__(self, mass, position, velocity):
self.m = mass
self.q = position
self.v = velocity
self.p = velocity*mass
def __repr__(self): # Called upon "print(body)"
return "Body of mass: {0:.2f}kg, position: {1}, velocity: {2}".format(self.m, self.p, self.v)
def __str__(self): # Called upon "str(body)"
return "Body of mass: {0:.2f}kg, position: {1}, velocity: {2}".format(self.m, self.p, self.v)
class System:
@@ -49,8 +54,7 @@ class System:
return L
#def initialize(self):
if __name__ == "__main__":
# initialisation mass
m1 = 10
m2 = 1
@@ -82,4 +86,3 @@ tribody = System([star1,star2,star3])
print("list=",Lbodylist)
print(tribody.Lval(Lbodylist))

0
lib/plots.py Normal file → Executable file
View File