DEV Community

Discussion on: Daily Challenge #233 - Get Planet Name by ID

Collapse
 
awwsmm profile image
Andrew (he/him) • Edited

switch statements don't exist in Python like they do in some other languages. We can use a dictionary instead:

def get_planet_name(id):
    switcher = {
        1: "Mercury",
        2: "Venus",
        3: "Earth",
        4: "Mars",
        5: "Jupiter",
        6: "Saturn",
        7: "Uranus",
        8: "Neptune"
    }
    return switcher.get(id, "Invalid Planet Index")