from space.planet import Planet from space.calc import planet_mass, planet_vol hoth = Planet('LEE', 20000, 5.6, 'HOHOHO') hoth_mass = planet_mass(hoth.gravity, hoth.radius) hoth_vol = planet_vol(hoth.radius) print(f'{hoth.name} has a mass of {hoth_mass} and volume of {hoth_vol}')
from space.planet import Planet from space.calc import planet_mass, planet_vol maher = Planet('maher', 200000, 5.5, 'Maher System') # print(f'Name is :{maher.name}') # print(f'Radius is : {maher.radius}') # print(f'The gravity is {maher.gravity}') # print(maher.orbit()) maher_mass = planet_mass(maher.gravity, maher.radius) maher_vol = planet_vol(maher.radius) print(f'{maher.name} has a mass of {maher_mass} and volume of {maher_vol} ') # planetX= Planet('planetX',300000,8,'X System') # print(f'Name : {planetX.name}') # print(f'Radius : {planetX.radius}') # print(f'Gravity : {planetX.gravity}') # print(planetX.orbit()) # print(planetX.commons()) # print(planetX.spin('a very high speed'))
from space.planet import Planet from space.calc import planet_mass, planet_vol naboo = Planet('Naboo', 300000, 8, 'Naboo System') naboo_mass = planet_mass(naboo.gravity, naboo.radius) naboo_vol = planet_vol(naboo.radius) print(f'{naboo.name} has a mass of {naboo_mass} and a volume of {naboo_vol}')
from space.planet import Planet from space.calc import planet_mass, planet_vol planet = Planet('Andy', 5000, 4.5, 'The system') planet_mass = planet_mass(planet.gravity, planet.radius) planet_vol = planet_vol(planet.radius) print( f'{planet.name} has a mass of {planet_mass} and a volume of {planet_vol}')
# hf = Planet('Hanfan', 200, 5.5, 'Hanfan system') # # print (f'Name is: {hf.name}') # print (f'Radius is: {hf.radius}') # print (f'Gravity is: {hf.gravity}') # # # orbit() is instance method, which is only has to be from the instance # print (hf.orbit()) # # # print (Planet.shape) # # # commons() is class method, can be accessed by Planet (can be used on the class itself) # print (Planet.commons()) # print (hf.commons()) # # # spin() is static method, can be accessed by Planet (can be used on the class itself) # print (Planet.spin('a very high speed')) # print (hf.spin('a very high speed')) from space.planet import Planet from space.calc import planet_mass, planet_vol hf = Planet('Hanfan', 200, 5.5, 'Hanfan system') hf_mass = planet_mass(hf.gravity, hf.radius) hf_vol = planet_vol(hf.radius) print(f'{hf.name} has a mass of {hf_mass} and a vol of {hf_vol}.')
from space.planet import Planet from space.calc import planet_mass, planet_vol mars = Planet('Mars', 300000, 8, 'Mars System') mars_mass = planet_mass(mars.gravity, mars.radius) mars_vol = planet_vol(mars.radius) print(f'{mars.name} has a mass of {mars_mass} and a volume of {mars_vol}') ''' class Planet: shape = 'round' #class level attr def __init__(self, name, radius, gravity, system): self.name = name #instance attr self.radius = radius #instance attr self.gravity = gravity #instance attr self.system = system #instance attr def orbit(self): #instance method return f'{self.name} is orbiting in the {self.system}' #class method: common for all our planets (class level attr) @classmethod def commons(cls): return f'All planets are {cls.shape} because of gravity' #static method: has no to class level attr,only has access to parameters we pass individually @staticmethod def spin(speed = '2000 miles per hour'):
#import package from space folder #planet is a class name from space from space.planet import Planet #import calc.py from space.calc import planet_mass, planet_vol allisa = Planet('allisa', 400000, 9.0, 'allisa system') allisa_mass = planet_mass(allisa.gravity, allisa.radius) allisa_vol = planet_vol(allisa.radius) print( f'{allisa.name} has a mass of {allisa_mass} and a volume of {allisa_vol} ')
from space.Planet import Planet from space.calc import planet_mass, planet_vol planetXR = Planet('Naboo', 300000, 8, 'Naboo system') # print(f'Name: {planetXR.name}') # print(planetXR.spin('very high speed')) planetXR_mass = planet_mass(planetXR.gravity, planetXR.radius) planetXR_vol = planet_vol(planetXR.radius) print( f'{planetXR.name} has a mass of {planetXR_mass} and volume {planetXR_vol}')
from space.planet import Planet from space.calc import planet_mass from space.calc import planet_vol x = Planet(name='Troy') juan_mass = planet_mass(x.gravity, x.radius) juan_vol = planet_vol(x.radius) print(f'Name is {x.name} has a mass of {juan_mass} and a volume of {juan_vol}') # print(juan_planet.orbit()) # print(juan_planet.shape) # plantX = Planet() # print(plantX.commons()) # print(plantX.spin(5000))
from space.planet import Planet from space.calc import planet_mass, planet_vol earth = Planet('Earth', 20000000, 8, 'Solar') earth_mass = planet_mass(earth.gravity, earth.radius) earth_vol = planet_vol(earth.radius) print(f'Earch has a mass like {earth_mass:.10f} and a vol like {earth_vol}')