Skip to content

Instantly share code, notes, and snippets.

# 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 = 0
for i in fileref:
num += len(i)
fileref.close()
# 2. We have provided a file called emotion_words.txt that contains lines of words that describe emotions.
#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 = []
# Open Workbook
workbook = Workbook("workbook.xlsx")
# Access the first worksheet
worksheet = workbook.getWorksheets().get(0)
# Add people name in column A. Fast name and Last name are separated by space.
worksheet.getCells().get("A1").putValue("John Teal")
worksheet.getCells().get("A2").putValue("Peter Graham")
worksheet.getCells().get("A3").putValue("Brady Cortez")