Github repo for the Course: Stanford Machine Learning (Coursera)
Quiz Needs to be viewed here at the repo (because the image solutions cant be viewed as part of a gist)
True or False | Statement | Explanation
# week_temps_f is a string with a list of fahrenheit temperatures separated by the , sign. | |
# Write code that uses the accumulation pattern to compute the average (sum divided by number of items) and assigns it to avg_temp. | |
# Do not hard code your answer (i.e., make your code compute both the sum or the number of items in week_temps_f) | |
# (You should use the .split(",") function to split by "," and float() to cast to a float). | |
week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7" | |
avg_temp = 0.0 | |
for i in week_temps_f: |
# addition_str is a string with a list of numbers separated by the + sign. | |
# Write code that uses the accumulation pattern to take the sum of all of the numbers and assigns it to sum_val (an integer). | |
# (You should use the .split("+") function to split by "+" and int() to cast to an integer). | |
addition_str = "2+5+10+20" | |
sum_val = 0 | |
for i in addition_str: | |
sum_val = sum(map(int,addition_str.split("+"))) | |
print(sum_val) |
# Write code to count the number of characters in original_str using the accumulation pattern and assign the answer to a variable num_chars. | |
# Do NOT use the len function to solve the problem (if you use it while you are working on this problem, comment it out afterward!) | |
original_str = "The quick brown rhino jumped over the extremely lazy fox." | |
num_chars = 0 | |
for i in original_str: | |
num_chars = num_chars + 1 | |
print(num_chars) |
# Write code that counts the number of words in sentence that contain either an “a” or an “e”. | |
# Store the result in the variable num_a_or_e. | |
# Note 1: be sure to not double-count words that contain both an a and an e. | |
# HINT 1: Use the in operator. | |
# HINT 2: You can either use or or elif. | |
# Hard-coded answers will receive no credit. | |
sentence = "python is a high level general purpose programming language that can be applied to many different classes of problems." | |
num_a_or_e = 0 |
# Write code that will count the number of vowels in the sentence s and assign the result to the variable num_vowels. | |
# For this problem, vowels are only a, e, i, o, and u. Hint: use the in operator with vowels. | |
s = "singing in the rain and playing in the rain are two entirely different situations but both can be fun" | |
vowels = ['a','e','i','o','u'] | |
# Write your code here. | |
num_vowels = sum([1 for i in s if i in vowels]) | |
print(num_vowels) |
# 1. Write code to add ‘horseback riding’ to the third position (i.e., right before volleyball) in the list sports. | |
sports = ['cricket', 'football', 'volleyball', 'baseball', 'softball', 'track and field', 'curling', 'ping pong', 'hockey'] | |
sports.insert(2, 'horseback riding') | |
# 2. Write code to take ‘London’ out of the list trav_dest. | |
trav_dest = ['Beirut', 'Milan', 'Pittsburgh', 'Buenos Aires', 'Nairobi', 'Kathmandu', 'Osaka', 'London', 'Melbourne'] | |
trav_dest.pop(7) |
# 1. Below are a set of scores that students have received in the past semester. | |
# Write code to determine how many are 90 or above and assign that result to the value a_scores. | |
scores = "67 80 90 78 93 20 79 89 96 97 92 88 79 68 58 90 98 100 79 74 83 88 80 86 85 70 90 100" | |
scores_split = scores.split(" ") | |
a_scores = 0 | |
for x in scores_split: | |
x = float(x) | |
if x >= 90: | |
a_scores += 1 |
Github repo for the Course: Stanford Machine Learning (Coursera)
Quiz Needs to be viewed here at the repo (because the image solutions cant be viewed as part of a gist)
True or False | Statement | Explanation
Github repo for the Course: Stanford Machine Learning (Coursera)
Quiz Needs to be viewed here at the repo (because the image solutions cant be viewed as part of a gist)
The American Community Survey distributes downloadable data about United States communities. Download the 2006 microdata survey about housing for the state of Idaho using download.file() from here:
https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv
and load the data into R. The code book, describing the variable names is here: