ONLY DO QUESTIONS 6-8 PLEASE Question 4 (COMPLETE: ''' 4. Let's find the "fireball" sighting(s) that lasted more than ten seconds in US. Print the the datetime and state of each. Put the data in "fball" and print the result. Note: Consider only the US sightings stored in "sightings_us". - Cast the duration in seconds to a float (decimal). - Check if duration is greater than 10. - Check if the shape is "fireball". ''' def is_valid_duration(duration_as_string): #eliminate duration values that don't have a valid duration # your code here try: duration = float(duration_as_string) except ValueError: return False else: return duration fball = [] # iterate through the sightings_us fball = [row for row in sightings_us if is_valid_duration(row["duration (seconds)"]) > 10 and row["shape"] == "fireball"] # output printing for row in fball: print(row['datetime'], row['state']) Question 5 (COMPLETE) ''' 5. Sort the above list by duration. What was the datetime and duration of the longest sighting? Put the sorted list in "fballsorted" and print the result. - Cast the duration in seconds to a float (decimal). - Sort in reverse order. ''' # your code here #cast duration in seconds to a float #sort the list by duration in reverse fballsorted = sorted(fball, key = lambda x: float(x['duration (seconds)']), reverse=True) for row in fballsorted: print((row['datetime'], row['duration (seconds)'])) Question 6 (STUCK) ''' 6. What state had the longest lasting "fireball"? Put the state in "state" and print the result. - Check if the shape is "fireball". - Cast the duration in seconds to a float (decimal). - Get the record with the largest (max) duration in seconds. - Get the state for the record. ''' # your code here #confirmfireball = [row for row in sightings_us if is_valid_duration(row["duration (seconds)"]) and row["shape"] == "fireball"] for row in sightings_us: # get the data for shape='fireball' having float of 'duration (seconds)' > 10 if row["shape"] == "fireball": #confirmfireball = [row for row in sightings_us if row["shape"] == "fireball"] valid_duration = [row for row in sightings_us if is_valid_duration(row["duration (seconds)"])] state = max(valid_duration, key = lambda x: float(x["duration (seconds)"])) print(state['duration (seconds)'], state['state']) Question 7 (STUCK) ''' 7. Let's assume that any sighting (of any shape) of 0 seconds is insignificant. Write code to filter out these extraneous records and get the shortest sighting overall now. Put the minimum duration in "min_duration" and print the result. Use ufosightings Note: Consider all sightings stored in "ufosightings". ''' # your code here Question 8 (STUCK) ''' 8. What are the top 3 shapes sighted, and how many sightings were there for each? Note: Consider all sightings stored in "ufosightings". - Create a new list "sightings_shapes" containing values from the "shape" column in ufosightings. - Create a new dictionary "count" with values of that column as keys and the counts as values. - Get a list of the dictionary keys and values using the items() method. This will return a list of key:value pairs. Sort the list of key:value pairs in reverse order, from greatest (most sightings) to least. Get the top 3 and store in "top3shapes". Print the result. ''' #Create a new list containing values from the "shape" column in ufosightings. # your code here #Create a new dictionary with values of that column as keys and the counts as values. # your code here #Get a list of the dictionary keys and values (use the items() method) and sort them in reverse order, from greatest (most sightings) to least. #Get and print the top 3. # your code here

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

ONLY DO QUESTIONS 6-8 PLEASE

Question 4 (COMPLETE:

 

'''

4. Let's find the "fireball" sighting(s) that lasted more than ten seconds in US. 

Print the the datetime and state of each. Put the data in "fball" and print the result.

 

Note: Consider only the US sightings stored in "sightings_us".

 

- Cast the duration in seconds to a float (decimal). 

- Check if duration is greater than 10. 

- Check if the shape is "fireball".

 

'''

def is_valid_duration(duration_as_string): #eliminate duration values that don't have a valid duration

# your code here

  try:

    duration = float(duration_as_string)

  

  except ValueError:

   

    return False

  else:

      return duration

 

fball = [] 

 

# iterate through the sightings_us

 

fball = [row for row in sightings_us if is_valid_duration(row["duration (seconds)"]) > 10 and row["shape"] == "fireball"]

 

 

# output printing

for row in fball:

  print(row['datetime'], row['state'])

 

Question 5 (COMPLETE)

 

'''

5. Sort the above list by duration. What was the datetime and duration of the longest sighting?  

Put the sorted list in "fballsorted" and print the result.

 

- Cast the duration in seconds to a float (decimal). 

- Sort in reverse order.

 

'''

 

# your code here

 

 

 

 

 

 

#cast duration in seconds to a float

 

 

#sort the list by duration in reverse

fballsorted = sorted(fball, key = lambda x: float(x['duration (seconds)']), reverse=True)

 

 

for row in fballsorted:

   

  print((row['datetime'], row['duration (seconds)']))

 

Question 6 (STUCK)

 

'''

6. What state had the longest lasting "fireball"?  Put the state in "state" and print the result.

 

- Check if the shape is "fireball".

- Cast the duration in seconds to a float (decimal).

- Get the record with the largest (max) duration in seconds.

- Get the state for the record.

'''

# your code here

 

#confirmfireball = [row for row in sightings_us if is_valid_duration(row["duration (seconds)"]) and row["shape"] == "fireball"]

 

for row in sightings_us:

   

   # get the data for shape='fireball' having float of 'duration (seconds)' > 10

  if row["shape"] == "fireball":

 

    #confirmfireball = [row for row in sightings_us if row["shape"] == "fireball"]

    valid_duration = [row for row in sightings_us if is_valid_duration(row["duration (seconds)"])]

 

    state = max(valid_duration, key = lambda x: float(x["duration (seconds)"]))

  

 

    print(state['duration (seconds)'], state['state'])          

          

 

Question 7 (STUCK)

 

'''

7. Let's assume that any sighting (of any shape) of 0 seconds is insignificant. 

Write code to filter out these extraneous records and get the shortest sighting overall now.  

Put the minimum duration in "min_duration" and print the result.  

Use ufosightings

Note: Consider all sightings stored in "ufosightings".

 

'''

 

# your code here

 

 

Question 8 (STUCK)

 

'''

8. What are the top 3 shapes sighted, and how many sightings were there for each? 

 

Note: Consider all sightings stored in "ufosightings".

 

- Create a new list "sightings_shapes" containing values from the "shape" column in ufosightings.  

- Create a new dictionary "count" with values of that column as keys and the counts as values.

- Get a list of the dictionary keys and values using the items() method. This will return a list of key:value pairs.

Sort the list of key:value pairs in reverse order, from greatest (most sightings) to least.

 

Get the top 3 and store in "top3shapes". Print the result.

 

'''

 

#Create a new list containing values from the "shape" column in ufosightings.

# your code here

 

 

#Create a new dictionary with values of that column as keys and the counts as values.

# your code here

 

     

#Get a list of the dictionary keys and values (use the items() method) and sort them in reverse order, from greatest (most sightings) to least.

#Get and print the top 3.

# your code here

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY