Skip to content
loading...

re: Daily Challenge #233 - Get Planet Name by ID VIEW POST

FULL DISCUSSION
 

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")
code of conduct - report abuse