# Sample Solution
import numpy as np
# Array of the first five author ages
five_author_ages = np.array([29, 49, 42, 43, 32])
# Fill in the empty array with the values sorted
sorted_author_ages = np.array([29, 32, 42, 43, 49])
# Save the median value to median_value
median_age = 42
# Print the sorted array and median value
print("The sorted array is: " + str(sorted_author_ages))
print("The median of the array is: " + str(median_age))
Quotes help make search much faster. Example: "Practice Makes Perfect"
Friday, August 30, 2019
Codecademy Learn Statistics With Python Exercise 3/4
# Sample Solution
# Import packages
import numpy as np
import pandas as pd
# Read author data
greatest_books = pd.read_csv("top-hundred-books.csv")
# Set author ages to a NumPy array
author_ages = greatest_books['Ages']
# Use numpy to calculate the average age of the top 100 authors
average_age = np.average(author_ages)
print("The average age of the 100 greatest authors, according to a survey by Le Monde, is: " + str(average_age))
# Import packages
import numpy as np
import pandas as pd
# Read author data
greatest_books = pd.read_csv("top-hundred-books.csv")
# Set author ages to a NumPy array
author_ages = greatest_books['Ages']
# Use numpy to calculate the average age of the top 100 authors
average_age = np.average(author_ages)
print("The average age of the 100 greatest authors, according to a survey by Le Monde, is: " + str(average_age))
Codecademy Learn Statistics With Python Exercise 2/4
# Sample Solution
# Set total equal to the sum
total = 29 + 49 + 42 + 43
# Set mean_value equal to the mean
mean_value = total / 4
# The following code prints the total and mean
print("The sum total is equal to: " + str(total))
print("The mean value is equal to: " + str(mean_value))
# Set total equal to the sum
total = 29 + 49 + 42 + 43
# Set mean_value equal to the mean
mean_value = total / 4
# The following code prints the total and mean
print("The sum total is equal to: " + str(total))
print("The mean value is equal to: " + str(mean_value))
Thursday, August 29, 2019
DataCamp Combining data types Sample Solution
# Update data types
year_1_str = str(year_1)
revenue_1_str = str(revenue_1)
# Create a complete sentence combining only the string data types
sentence = 'The revenue of ' + company_1 + ' in ' + year_1_str + ' was $' + revenue_1_str + ' billion.'
# Print sentence
print(sentence)
year_1_str = str(year_1)
revenue_1_str = str(revenue_1)
# Create a complete sentence combining only the string data types
sentence = 'The revenue of ' + company_1 + ' in ' + year_1_str + ' was $' + revenue_1_str + ' billion.'
# Print sentence
print(sentence)
DataCamp Booleans in Python Sample Solution
# Test equality
test_company = 'apple'
print(company_1 == test_company)
# Compare revenue_1 and revenue_2
print(revenue_1 > revenue_2)
test_company = 'apple'
print(company_1 == test_company)
# Compare revenue_1 and revenue_2
print(revenue_1 > revenue_2)
DataCamp Determining types Sample Solution
# Type of company_1
print(type(company_1))
# Type of year_1
print(type(year_1))
# Type of revenue_1
print(type(revenue_1))
print(type(company_1))
# Type of year_1
print(type(year_1))
# Type of revenue_1
print(type(revenue_1))
DataCamp Creating variables Sample Solution
# Create company_1
company_1 = 'Apple'
print(company_1)
# Create year_1
year_1 = 2017
print(year_1)
# Create revenue_1
revenue_1 = 229.23
print(revenue_1)
company_1 = 'Apple'
print(company_1)
# Create year_1
year_1 = 2017
print(year_1)
# Create revenue_1
revenue_1 = 229.23
print(revenue_1)
Subscribe to:
Posts (Atom)
This is an example of scrolling text using Javascript.
Popular Posts
-
<html> <head> <!-- Add the Parse SDK here! --> <script src="http://www.parsecdn.com/js/par...
-
$("#tours > li")
-
Answer: Alt - p p stands for previous. If you keep pressing Alt - p, you will continue cycling back through commands you typed before. I...
-
<!-- Sample solution to index.html --> <!DOCTYPE html> <html> <body> <div class="nav"> ...
-
//sample solution def isEven(x): if(x % 2 == 0): return "yep" else: return "nope"
-
<!--sample solution--> <html> <head> <title>Week 13 Project</title> </head> ...
-
#sample solution hungry = false unless hungry puts "I'm writing Ruby programs!" else puts "Time to eat!...
-
//sample solution var yourName = "Pam"; var gender = "female"; var result; //Line 10 starts an if statement //Ne...
-
function isCorrectColumn(sudoku, col) { // This method should return true if all the numbers from 1 to 9 // are present in the co...
-
#sample solution Webster = { "Aardvark" : "A star of a popular children's cartoon show.", "Baa...