Build a Planet Class - Build a Planet Class

Tell us what’s happening:

Q18.
I have tried several ways to call the orbit method on the planet objects but still not passing. kindly advise

Your code so far

class Planet:
  def __init__(self, name, planet_type, star):

    self.name = name
    self.planet_type = planet_type
    self.star = star

    if not isinstance(name, str):
      raise TypeError("name, planet type, and star must be strings")
    if not isinstance(planet_type, str):
      raise TypeError("name, planet type, and star must be strings")
    if not isinstance(star, str):
      raise TypeError("name, planet type, and star must be strings")

    if name == '':
      raise ValueError("name, planet_type, and star must be non-empty strings")
    if planet_type == '':
      raise ValueError("name, planet_type, and star must be non-empty strings")
    if star == '':
      raise ValueError("name, planet_type, and star must be non-empty strings")

  def orbit(self):
    return f"{self.name} is orbiting around {self.star}..."

  def __str__(self):
    return f"Planet: {self.name} | Type: {self.planet_type} | Star: {self.star}"

planet_1 = Planet('Mercury', 'terrestrial', 'Sun')
planet_2 = Planet('Neptune', 'ice giant', 'Sun')
planet_3 = Planet('Proxima Centauri b', 'super-Earth', 'Proxima Centauri')

print(planet_1)
print(planet_2)
print(planet_3)

planet_1.orbit()
planet_2.orbit()
planet_3.orbit()




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Planet Class - Build a Planet Class

i got it, i had to add the print call at each orbit call

What is the different between this code and your code: class Planet:
def init(self, name, planet_type, star):

    self.name = name
    self.planet_type = planet_type
    self.star = star

    if not isinstance(name, str):
        raise TypeError("name, planet type, and star must be strings")
    if not isinstance(planet_type, str):
        raise TypeError("name, planet type, and star must be strings")
    if not isinstance(star, str):
        raise TypeError("name, planet type, and star must be strings")

    if name == '':
        raise ValueError("name, planet_type, and star must be non-empty strings")
    if planet_type == '':
        raise ValueError("name, planet_type, and star must be non-empty strings")
    if star == '':
        raise ValueError("name, planet_type, and star must be non-empty strings")

# Step 14: fix orbit method to have exactly 4 dots
def orbit(self):
    return f"{self.name} is orbiting around {self.star}...."

def __str__(self):
    return f"Planet: {self.name} | Type: {self.planet_type} | Star: {self.star}"

planet_1 = Planet(‘Mercury’, ‘terrestrial’, ‘Sun’)
planet_2 = Planet(‘Neptune’, ‘ice giant’, ‘Sun’)
planet_3 = Planet(‘Proxima Centauri b’, ‘super-Earth’, ‘Proxima Centauri’)

print(planet_1)
print(planet_2)
print(planet_3)

Step 19: print the result of orbit() method for each planet

print(planet_1.orbit())
print(planet_2.orbit())
print(planet_3.orbit())

if you need help create your own topic please

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.