Question

In: Computer Science

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 2 (5 points)
# Output a set containing the ages of all the superheroes.
# Output the name and the age of the youngest superhero.
# Sample output is below.

Set of all ages: {39, 1000, 1167, 2352, 27, 29}
Doomguy is 27 years old.

Solutions

Expert Solution

Here I have implemented python3 code which is print the output as per your given format. also, I have attached a screenshot of the output. please let me know in the comment section if you have any queries regarding the below code.


import sys

# Given dictionary
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"
]
} ,
  
}


# initialize with maxvalue
min_age=sys.maxsize

# Name of minimum age superHero
name=''

# set which stores all superHeroes age
age=set()

# loop over the whole dictionary   
for i in superHeroes:
    
    # current index superHero's age
    tmp=superHeroes[i]['age']
    
    # add age into a set of age    
    age.add(tmp)
    
    # find minimum age superHero
    if tmp<min_age:
        min_age=tmp
        name=i

# print output as per given format
print('Set of all ages:',age)
print('{} is {} years old.'.format(name,min_age))

Output:


Related Solutions

#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
Dan, age 45, is an independent contractor working in pharmaceutical sales, Cheryl, age 42, is a...
Dan, age 45, is an independent contractor working in pharmaceutical sales, Cheryl, age 42, is a nurse at a local hospital. Dan’s ssn is 400-20-100 and Cheryl’s SSN is 200-40-8000 an they reside at 2033 Palmetto Drive, Atlanta, GA 30304. Dan is paid according to commissions from sales, and he has no income tax or payroll tax withholdings. Dan operates his business from his home office. During 2018 Dan earned total commission in his business of $125,000. Cheryl earned a...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer Protocol (FTP) application that transmits files between a client and a server using Python. Your programs should implement four FTP commands: (1) change directory (cd), (2) list directory content (ls), (3) copy a file from client to a server (put) and (4) copy a file from a server to a client (get). Implement two versions of the program: one that uses stock TCP for...
Using python, produce code that mimics some ATM transactions: a. A welcome message must be displayed...
Using python, produce code that mimics some ATM transactions: a. A welcome message must be displayed initially reflecting the appropriate time of day (for example: Good Night, Welcome to Sussex Bank). b. Assume the user’s account balance is $5375.27. c. Allow the user to enter a pin number that does not have to be validated: def atm_login(): pin_number = input("Please enter your (4 digit) pin number: ") # display welcome message welcome_message() d. The message should be followed by a...
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow...
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers,...
Susie maintains a household that includes a daughter (age 29) and a cousin (age 28). Susie...
Susie maintains a household that includes a daughter (age 29) and a cousin (age 28). Susie says that she can claim the cousin as a dependent, but not her daughter. Could Susie be correct? Discuss the dependency exemption rules and how they would apply to this scenario.
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT