This file contains hidden or 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
| # 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] | |
This file contains hidden or 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
| #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 = [] |
This file contains hidden or 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
| # 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) |
This file contains hidden or 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
| # 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. |
NewerOlder