Question

THE CODE MUST BE PYTHON superHeroes = {   "MoleculeMan": {       "age": 29,       "secretIdentity": "Dan Jukes",       "superpowers":...

THE CODE MUST BE PYTHON

superHeroes = {

  "MoleculeMan": {

      "age": 29,

      "secretIdentity": "Dan Jukes",

      "superpowers": [

        "Radiation Immunity",

        "Turning tiny",

        "Radiation blast"

      ]

    },

  "MadameUppercut": {

      "age": 39,

      "secretIdentity": "Jane Wilson",

      "superpowers": [

        "Million tonne punch",

        "Damage resistance",

        "Superhuman reflexes"

      ]

    },

  "EternalFlame": {

      "age": 1000,

      "secretIdentity": "Unknown",

      "superpowers": [

        "Immortality",

        "Heat Immunity",

        "Inferno",

        "Teleportation",

        "Interdimensional travel"

      ]

    },

  "Doomguy": {

      "age": 27,

      "secretIdentity": "Space Trooper",

      "superpowers": [

        "Immortality",

        "Heat Immunity",

        "Teleportation",

        "Super Speed",

        "Superhuman reflexes"

      ]

  },

  "Maui":{

       "age": 2352,

      "secretIdentity": "Unknown",

      "superpowers": [

        "Immortality",

        "Super Speed"

      ]

  },

  "Superwoman":{

      "age": 1167,

      "secretIdentity": "Lois Lane",

      "superpowers": [

        "Immortality",

        "Super Speed",

        "Superhuman reflexes"

      ]

  } ,

  }

# Question 3 (4 points)

# Output the names of all the superheros that have "Superhuman reflexes" as one of their superpowers.

# Sample output is below.

Doomguy Superwoman

Homework Answers

Answer #1

Kindly refer to the code snippet below.

//function for finding the super hero names and return as a list

def get_SuperHero_Names(superPower):
    SHNames=superHeros.keys()                          // It will fetch all the keys for 
                                                       //inner dictionaries
    newList=[]
    for name in SHNames:                               // iterate over all the keys of 
                                                       // inner dictionaries

        for power in (superHeros[name]['superpowers']):// Access the particular value of 
                                                       // inner dictionary through indexing

            if(power==superPower):                     // if criteria matches 
                newList.append(name)                   // then store the key of outer 
                                                       // dictionary(superhero)into list

    return newList

//driver code
print(get_SuperHero_Names('Superhuman reflexes'))    
print(get_SuperHero_Names('Super Speed'))                

Also kindly refer to the code and output screenshot below for better understanding of code indentation:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT