Build a Planet Class - Build a Planet Class

Tell us what’s happening:

i’m getting the desired output bit sm getting the following error messages:

4. The __init__ method should raise a TypeError with the message name, planet type, and star must be strings if the first argument passed in is not a string type.
5. The __init__ method should raise a TypeError with the message name, planet type, and star must be strings if the second argument passed in is not a string type.
6. The __init__ method should raise a TypeError with the message name, planet type, and star must be strings if the third argument passed in is not a string type.
7. The __init__ method should raise a ValueError with the message name, planet_type, and star must be non-empty strings if the first argument passed in is an empty string.
8. The __init__ method should raise a ValueError with the message name, planet_type, and star must be non-empty strings if the second argument passed in is an empty string.
9. The __init__ method should raise a ValueError with the message name, planet_type, and star must be non-empty strings if the third argument passed in is an empty string.
14. The orbit method should return a string in the format {name} is orbiting around {star}....
// tests completed
// console output
Planet: Mercury | Type: Ice | Star: Sun
Planet: Saturn | Type: Giant | Star: Sun
Planet: Jupiter | Type: Giant | Star: Sun


Mercury is orbiting around Sun
Saturn is orbiting around Sun
Jupiter is orbiting around Sun

I don’t know what i’m doing wrong. here’s my code:

Your code so far

class Planet:
    def __init__(self,name,planet_type,star):
        if name == "":
            raise TypeError(f'name, planet type, and star must be strings')
        if planet_type == '':
            raise TypeError(f'name, planet type, and star must be strings')
        if star == "":
            raise TypeError(f'name, planet type, and star must be strings')
        
        if not isinstance(name,str):
            raise ValueError(f'name, planet_type, and star must be non-empty string')
        
        if not isinstance(name,str):
            raise ValueError(f'name, planet_type, and star must be non-empty string')
        
        if not isinstance(name,str):
            raise ValueError(f'name, planet_type, and star must be non-empty string')

        self.name  = name
        self.planet_type = planet_type
        self.star = star
    
    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","Ice","Sun")
planet_2 = Planet("Saturn","Giant","Sun")
planet_3 = Planet("Jupiter","Giant","Sun")

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

print("\n")

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15

Challenge Information:

Build a Planet Class - Build a Planet Class

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-planet-class/68e76b1ce8216249d04df670.md at main · freeCodeCamp/freeCodeCamp · GitHub

Please check these parts. You are raising the wrong exceptions and error messages.

  • Raise a TypeError with the message:
    name, planet_type, and star must be strings
    if any of the arguments is not a string.
  • Raise a ValueError with the message:
    name, planet_type, and star must be non-empty strings
    if any of the arguments is an empty string.

However, your implementation is reversed. You are raising a TypeError for empty strings and a ValueError for non-string values. Please swap these checks so they match the required behavior.