DEV Community

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

Collapse
 
shandytp profile image
Moch Shandy Tsalasa Putra • Edited

I'm gonna do the traditional way:

def get_planet_name_by_id(id):
    if id == 1:
        return "Mercury"
    elif id == 2:
        return "Venus"
    elif id == 3:
        return "Earth"
    elif id == 4:
        return "Mars"
    elif id == 5:
        return "Jupiter"
    elif id == 6:
        return "Saturn"
    elif id == 7:
        return "Uranus"
    elif id == 8:
        return "Neptune"
    return "Planet Index doesn't exist"
Collapse
 
fluffynuts profile image
Davyd McColl

this is the correct answer (: Python intentionally shunned the switch statement because it's easy to make mistakes, especially with languages which allow fall-through (: