Question: Python code : Having problems with option 2 import pickle def main(): degrees = {} input_file = open('DegreesDict.dat','rb') degrees = pickle.load(input_file) print( Bachelor Degrees Menu)
Python code : Having problems with option 2
import pickle
def main(): degrees = {} input_file = open('DegreesDict.dat','rb') degrees = pickle.load(input_file) print(" Bachelor Degrees Menu") print("---------------------") print("1. Bachelor Degrees conferred in certain fields") print("2. Percentage change in bachelor degrees conferred") print("3. Bachelor Deegrees conferred in 2010 in certain fields") print("4. Exit from Menu") option = int(input("Enter your option(1,2,3,4): ")) if option == 1: print(" Bachelor Degree conferred in certain fields") print("--------------------------------------------------------------------") print('{:30}'.format("Field of Study"),'{:10}'.format('1981'),'{:10}'.format('2010')) print("--------------------------------------------------------------------") number1 = "" number2 = "" keyList = list(degrees.keys()) keyList.sort() for i in range(len(keyList)): string = degrees[keyList[i]] b = True a = True q = '(' newString = str(string) newString1 = newString.lstrip(q) for char in newString1: if char.isdigit() and b and a: number2 += char elif char.isdigit() and b: number1 += char else: a = False print('{:30}'.format(keyList[i]),'{:10}'.format(number2),'{:10}'.format(number1)) i += 1 number1 = "" number2 = "" elif option == 2: print(" Perchange change in bachelor degrees conferred") print("-----------------------------------------------------------------") print("{0:
3 elif option == 3: deg_2010 = {} print(" Bachelor degrees conferred in 2010 in certain fields") print("------------------------------------------------------") number1 = "" number2 = "" keyList = list(degrees.keys()) for i in range(len(keyList)): string = degrees[keyList[i]] b = True a = True q = '(' newString = str(string) newString1 = newString.lstrip(q) for char in newString1: if char.isdigit() and b and a: number2 += char elif char.isdigit() and b: number1 += char else: a = False number3 = int(number1) number4 = int(number2) deg_2010[number3] = keyList[i] i += 1 number1 = "" number2 = "" pList = list(deg_2010.keys()) pList.sort() sList = [0,0,0,0,0] i = 0 dList = ['','','','','',] for i in range(len(pList)): sList[i] = int(pList[i] / 10000)
i = 0 for i in range(len(pList)): for e in range(sList[i]): dList[i] += '*' for v in range(len(pList)): print('{:30}'.format(deg_2010[pList[v]]),dList[v],pList[v]) elif option == 4: exit() else: print('Invalid option. Try again') main()

Bachelor Degrees Table 5.8 shows the number of bachelor degrees conferred in 1981 and 2010 in certain fields of study. Tables 5.9 and 5.10 show the percentage change and a histogram of 2010 levels, respectively. Write a program that allows the user to display any one of these tables as an option and to quit as a fourth option. Table 5.8 is ordered alphabetically by field of study, Table 5.9 is ordered by decreasing percentages, and Table 5 is ordered by increasing number of degrees. Use the file DegreesDict.dat that stores a dictionary where each field of study is a key and each value is a two-tuple of the form (number of degrees in 1981, number of degrees in 2010). One item of the dictionary is "Business" (200521,358293). TABLE 5.8 Bachelor degrees conferred in certain fields Field of Study 1981 2010 Business 200,521 358,293 Computer and info. science 15,121 39,589 Education 108,074 101,265 Engineering 63,642 72,654 Social sciences and history 100,513 172,780 Soence: National Center for Education Statistics. TABLE 5.9 Percentage change in bachelor degrees conferred. Field of Study Change (1981-2010) Computer and info. science 161.8% Business 78.7% Social sciences and history 71.9% Engineering 14.2% Education 6.3% TABLE 5.10 Bachelor degrees conferred in 2010 in certain fields. Computer and info. science 39,589 Engineering 72,654 Education 101,265 Social sciences and history 172,780 Business ******************************h 358,293
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
