This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task 1: Create a project jumphost instance | |
Make sure you: | |
name the instance -- nucleus-jumphost | |
use the machine type -- f1-micro | |
use the default image type (Debian Linux) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rainfall_mi is a string that contains the average number of inches of rainfall in | |
# Michigan for every month (in inches) with every month separated by a comma. | |
# Write code to compute the number of months that have more than 3 inches of rainfall. | |
# Store the result in the variable num_rainy_months. In other words, count the number of items with values > 3.0. | |
rainfall_mi = "1.65, 1.46, 2.05, 3.03, 3.35, 3.46, 2.83, 3.23, 3.5, 2.52, 2.8, 1.85" | |
rainfall_mi1 = rainfall_mi.split(",") | |
num_rainy_month = 0 | |
for x in rainfall_mi1: | |
x = float(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: | |
avg_temp = sum(map(float,week_temps_f.split(","))) / 7 | |
print(avg_temp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write code that uses iteration to print out the length of each element of the list stored in str_list. | |
str_list = ["hello", "", "goodbye", "wonderful", "I love Python"] | |
# Write your code here. | |
for i in range(len(str_list)): | |
print(len(str_list[i])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write one for loop to print out each element of the list several_things. | |
# Then, write another for loop to print out the TYPE of each element of the list several_things. | |
# To complete this problem you should have written two different for loops, | |
# each of which iterates over the list several_things, but each of those 2 for loops should have a different result. | |
several_things = ["hello", 2, 4, 6.0, 7.5, 234352354, "the end", "", 99] | |
for i in range(len(several_things)): | |
print(several_things[i]) | |
for j in range(len(several_things)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write one for loop to print out each character of the string my_str on a separate line. | |
my_str = "MICHIGAN" | |
for i in range(len(my_str)): | |
print(my_str[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What will the output be for the following code? | |
ls = ['run', 'world', 'travel', 'lights', 'moon', 'baseball', 'sea'] | |
new = ls[2:4] | |
print(new) | |
# output | |
['travel', 'lights'] | |
# python is a zero-index based language and slices are inclusive of the first index and exclusive of the second. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write code that combines the following variables so that the sentence | |
# “You are doing a great job, keep it up!” is assigned to the variable message. | |
# Do not edit the values assigned to by, az, io, or qy. | |
by = "You are" | |
az = "doing a great " | |
io = "job" | |
qy = "keep it up!" | |
message = (by+' '+az+io+','+' '+qy) | |
print(message) |
NewerOlder