Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, August 31, 2019

Codecademy Learn Statistics With Python Quartiles Exercise 5/6


# Sample Solution
from song_data import songs
import numpy as np

#Create the variables songs_q1, songs_q2, and songs_q3 here:
songs_q1 = np.quantile(songs, 0.25)
songs_q2 = np.quantile(songs, 0.50)
songs_q3 = np.quantile(songs, 0.75)
number_of_songs = len(songs)
print("There are " + str(number_of_songs) + " songs in this list.")
#Generate a random number to pick a favorite song
import random
random_num = random.randint(0,(number_of_songs-1))
favorite_song = songs[random_num]
print("Song length in seconds is " + str(favorite_song))
if(favorite_song < songs_q1):
  quarter = 1 
elif(favorite_song < songs_q2):
  quarter = 2
elif(favorite_song < songs_q3):
  quarter = 3
else:
  quarter = 4
print("Favorite song is in quartile " + str(quarter))
#Ignore the code below here:
try:
  print("The first quartile of dataset one is " + str(songs_q1) + " seconds")
except NameError:
  print("You haven't defined songs_q1")
try:
  print("The second quartile of dataset one is " + str(songs_q2)+ " seconds")
except NameError:
  print("You haven't defined songs_q2")
try:
  print("The third quartile of dataset one is " + str(songs_q3)+ " seconds")
except NameError:
  print("You haven't defined songs_q3\n")

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts