openedFile = False while (not openedFile): #Openfile is false so runs this program until true fileName = input("Open what file: ") #Input the filename to open output_file = open("BLS_private.csv",'r') #Opens an empty output file to write the desired information try: file = open(fileName,'r') #Try's to open the file that was inputted in by user openedFile = True #If that file name exist the openedFile is true and can exit the loop except IOError: #When there is an IOError then that file doesn't exist so makes program print... print("Bad file name, try again ") #This comment when the file doesn't exist. Then loop restarts. for i in range (11): #This gets rid of first few lines in code because it is useless information output_file.readline() L = [] #Empty List for line in output_file: #Opening output file line = line.strip() #Make a list of everything line_list = line.split(',') L.append(line_list) president_list = [] #Empty List for line in file: #Make a list of everythin line = line.strip() line = line.split() president_list.append(line) month_list = ['Year', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] master_list = [] for i in range(10): dog = president_list[i][3] #Grabs the months of when presidents elected and leave presidency sheep = president_list[i][4] #Grabs the years the presidents elected and leave presidency for line in L: for ch in line: if ch == sheep: #When the year is the same in the list as the selected presidents year number = [i for i,x in enumerate(month_list) if x == dog] #Finds the month in the output file that is the selected one from the president file k = number[0] #Correlates a number to the month by using the created month list above. l = line[k] #With this is selected the correct value in the excel worksheet master_list.append(l) #Appends that too the list. chicken = president_list[i][-1] #Finds if the president is democratic of republican master_list.append(chicken) #Adds it to the master list master_list.append('111744') #Adds obama current number of jobs he is at this moment master_list.append('Democrat') #Adds that he is democratic x = 2 v = 1 y = 0 pres_job_list = [] #Bunch of empty list and what not w = len(master_list)-1 w = int(w/2) Republicans = [] Democrats = [] tnr = [] tnd = [] for i in range(w): z = int(master_list[x]) - int(master_list[y]) #Subtracts the number of jobs in the beginning of a presidency and the number of jobs in the end of the presidency h = master_list[v] #Finds out if that number should be democratic or republican x+=2 y+=2 pres_job_list.append(z) #Appends all the number of increase or decreases in jobs over each presidents presidency for i in range(10): p = president_list[i][-1] #Finds of president is republican or democratic if p == 'Republican': t = president_list[i][0:3] #Adds the republican presidents name x = (pres_job_list[i])/1000 #Makes the number of jobs into millions instead of thousands z = t[0]+' '+t[1]+ ' '+t[2] +': Increase of' + ' ' + str(x)+ ' ' + 'million jobs' tnr.append(x) #Adds the numbers of republican increase/decrease to list... Used for total increase Republicans.append(z) #Adds the president and his number of increase/decrease in jobs during presidency to a list if p == 'Democrat': t = president_list[i][0:3] #Does the same thing except for the democratic presidents x = (pres_job_list[i])/1000 z = t[0]+' '+t[1]+ ' '+t[2] +': Increase of' + ' ' + str(x)+ ' ' + 'million jobs' tnd.append(x) Democrats.append(z) total_rep = tnr[0]+tnr[1]+tnr[2]+tnr[3]+tnr[4] #Adds them all up to find the total republican increase/decrease in jobs total_dem = tnd[0]+tnd[1]+tnd[2]+tnd[3]+tnd[4] #Adds them all up to find the total democratic increase/decrease in jobs print("Let's cut to the chase. According to the Bureau of Labor Statistics,") print("here are the net increases in private-sector employment under each president, chronologically by party:") print(' '*40) print("Republicans") print(' '*40) for line in Republicans: print(line) print(' '*40) print("Total: Increase of" + ' ' + str(total_rep) + ' ' +'million jobs under the Republican presidents') print(' '*40) print("Democrats") print(' '*40) for line in Democrats: print(line) print(' '*40) print("Total: Increase of" + ' ' + str(total_dem) + ' ' +'million jobs under the Democratic presidents') print(' '*40) print("So Clinton is right.")