Skip to content

Instantly share code, notes, and snippets.

@guestPK1986
guestPK1986 / course_2_assessment_1.py
Last active August 7, 2020 00:53
course_2_assessment_1
# 1. The textfile, travel_plans.txt, contains the summer travel plans for someone with some commentary.
# Find the total number of characters in the file and save to the variable num.
fileref = open("travel_plans.txt","r")
num =len(file.read())
fileref.close()
# 2. We have provided a file called emotion_words.txt that contains lines of words that describe emotions.
# Find the total number of words in the file and assign this value to the variable num_words.
@guestPK1986
guestPK1986 / course_2_assessment_2.py
Last active August 4, 2020 17:27
course_2_assessment_2
# 1. At the halfway point during the Rio Olympics, the United States had 70 medals, Great Britain had 38 medals, China had 45 medals, Russia had 30 medals, and Germany had 17 medals. Create a dictionary assigned to the variable medal_count with the country names as the keys and the number of medals the country had as each key’s value.
medal_count = {'United States': 70, 'Great Britain': 38, 'China': 45, 'Russia': 30, 'Germany': 17}
print(medal_count)
# 2. Given the dictionary swimmers, add an additional key-value pair to the dictionary with "Phelps" as the key and the integer 23 as the value. Do not rewrite the entire dictionary.
swimmers = {'Manuel':4, 'Lochte':12, 'Adrian':7, 'Ledecky':5, 'Dirado':4}
swimmers['Phelps'] = 23
print(swimmers)
#Read in the contents of the file SP500.txt which has monthly data for 2016 and 2017
#about the S&P 500 closing prices as well as some other financial indicators,
#including the “Long Term Interest Rate”, which is interest rate paid on 10-year U.S. government bonds.
#Write a program that computes the average closing price (the second column, labeled SP500)
#and the highest long-term interest rate. Both should be computed only for the period from June 2016 through May 2017.
#Save the results in the variables mean_SP and max_interest
with open("SP500.txt", "r") as file:
new = file.readlines()
closing_price = []
@guestPK1986
guestPK1986 / course_2_assessment_3.py
Created August 8, 2020 02:00
course_2_assessment_3
# 1. The dictionary Junior shows a schedule for a junior year semester.
# The key is the course name and the value is the number of credits.
# Find the total number of credits taken this semester and assign it to the variable credits.
# Do not hardcode this – use dictionary accumulation!
Junior = {'SI 206':4, 'SI 310':4, 'BL 300':3, 'TO 313':3, 'BCOM 350':1, 'MO 300':3}
credits = 0
for x in Junior:
credits = credits + Junior[x]
@guestPK1986
guestPK1986 / course_1_assessment_7.py
Created August 19, 2020 02:09
course_1_assessment_7
#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"
file = rainfall_mi.split(",")
print(file)
num_rainy_months = 0
for x in file:
@guestPK1986
guestPK1986 / course_1_assessment_8.py
Created August 19, 2020 04:23
course_1_assessment_8
#Create one conditional so that if “Friendly” is in w, then “Friendly is here!” should be assigned to the variable wrd.
#If it’s not, check if “Friend” is in w. If so, the string “Friend is here!” should be assigned to the variable wrd,
#otherwise “No variation of friend is in here.” should be assigned to the variable wrd
w = "Friendship is a wonderful human experience!"
for x in w:
if "Friendly" in w:
wrd = str("Friendly is here!")
elif "Friend" in w:
wrd = str("Friend is here!")
@guestPK1986
guestPK1986 / course_1_assessment_9_py
Created August 21, 2020 23:15
course_1_assessment_9
# 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)
@guestPK1986
guestPK1986 / functions.py
Created August 23, 2020 01:25
python functions
#Write a function named total that takes a list of integers as input,
#and returns the total value of all those integers added together.
def total(lst):
accum=0
for x in lst:
accum=accum+x
return accum
lst=[1,2,3,4]
total(lst)
#Provided is a list of tuples. Create another list called t_check that contains the third element of every tuple.
lst_tups = [('Articuno', 'Moltres', 'Zaptos'), ('Beedrill', 'Metapod', 'Charizard', 'Venasaur', 'Squirtle'), ('Oddish', 'Poliwag', 'Diglett', 'Bellsprout'), ('Ponyta', "Farfetch'd", "Tauros", 'Dragonite'), ('Hoothoot', 'Chikorita', 'Lanturn', 'Flaaffy', 'Unown', 'Teddiursa', 'Phanpy'), ('Loudred', 'Volbeat', 'Wailord', 'Seviper', 'Sealeo')]
t_check = []
for x in lst_tups:
t_check.append(x[2])
print (t_check)
#Below, we have provided a list of tuples.
@guestPK1986
guestPK1986 / bash-cheatsheet.sh
Created August 26, 2020 14:23 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04