How to solve these 2 functions in python 3.6? Storm: we will always use the foll
ID: 3857328 • Letter: H
Question
How to solve these 2 functions in python 3.6?
Storm: we will always use the following representation for a storm inside our programs: a tuple containing these values in this order. Note that name is a string, but all other fields must be stored as integers. (Also, though a storm occurs in a specific year, notice we don't see it here- that's because it will be represented elsewhere in a database, and duplicated information is rarely a good idea in a database). sample storm(name, category, deathtoll, cost in millions)Explanation / Answer
Hi,
here are the implementation of two functions :
#!/usr/bin/python
sample_db = {
1992: [('Andrew', 52, 62, 66730)],
2004: [('Indra', 5, 902, 233), ('sandy', 23, 78, 21767) ]
}
cost_year = 0;
dead_year = 0
key_costliest = 0
key_deadliest = 0
def costliest_year(db) :
global cost_year
for key,value in db.items():
for l in db[key]:
if ( l[3] > cost_year ):
cost_year = l[3]
key_costliest = key
return key_costliest
def deadliest_year(db):
global dead_year
for key,value in db.items():
for l in db[key]:
if ( l[2] > dead_year ):
dead_year = l[2]
key_deadliest = key
return key_deadliest
key_cost = costliest_year(sample_db)
key_dead = deadliest_year(sample_db)
print key_cost
print " "
print key_dead
Thanks
Nikhil Jain
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.