def FreqNames(mess): try: inf = open( 'C:\\Users\\ale\\PycharmProjects\\WorkbookExercises\\Files\\Popular_Baby_Names.csv' ) yearsm = {} yearsf = {} for l in inf: line = inf.readline() arr = splitWords(line) if arr[0] not in yearsm and arr[1] == 'MALE': yearsm.setdefault(arr[0], []) yearsm[arr[0]].append(arr[len(arr) - 3]) elif arr[0] in yearsm and arr[1] == 'MALE': yearsm[arr[0]].append(arr[len(arr) - 3]) elif arr[0] not in yearsf and arr[1] == 'FEMALE': yearsf.setdefault(arr[0], []) yearsf[arr[0]].append(arr[len(arr) - 3]) elif arr[0] in yearsf and arr[1] == 'FEMALE': yearsf[arr[0]].append(arr[len(arr) - 3]) except FileNotFoundError: return print('Something went wrong, the program wil quit') return yearsm[mess], yearsf[mess]
def listof(list): list = list string = '' a = 0 for i in list: y = splitWords(i) while a <= len(y): if a < len(y) - 2: string = string + y[a] + ',' + ' ' elif a == len(y) - 2: string = string + y[a] + ' ' + 'and' + ' ' elif a == len(y) - 1: string = string + y[a] + '.' + '\n' a = a + 1 a = 0 return string
def FreqNamesTot(): try: inf = open('C:\\Users\\ale\\PycharmProjects\\WorkbookExercises\\Files\\Popular_Baby_Names.csv') yearsm = [] yearsf = [] for l in inf: line = inf.readline() line = line.upper() arr = splitWords(line) if arr[len(arr) - 3] not in yearsm and arr[1] == 'MALE': yearsm.append(arr[len(arr) - 3]) if arr[len(arr) - 3] not in yearsf and arr[1] == 'FEMALE': yearsf.append(arr[len(arr) - 3]) except FileNotFoundError: return print('Something went wrong, the program wil quit') return yearsm, yearsf
from ex117 import splitWords import sys inp = input('Enter the words you want to check:') if len(sys.argv) != 2: print( "Error in searching your checker file, no argument provided, the program will quit." ) quit() try: inf = open(sys.argv[1], 'r') check = inf.read() check = check.lower() words = splitWords(inp) errors = [] for w in words: if w in check: pass else: errors.append(w) print(errors) except FileNotFoundError: print('Something went wrong with your check file, the program wil quit') quit()
from ex117 import splitWords alph = {} perc = {} try: inf = open( 'C:\\Users\\ale\\PycharmProjects\\WorkbookExercises\\Files\\String.txt' ) inf = inf.read() words = splitWords(inf) print(words) tot = 0 for w in words: for l in w: l = l.lower() if l not in alph and 'a' <= l <= 'z': alph[l] = 1 tot = tot + 1 elif 'a' <= l <= 'z': alph[l] = alph[l] + 1 tot = tot + 1 for l in alph: a = round(alph[l] * 100 / tot, 2) perc[l] = str(a) + '%' print(perc) except FileNotFoundError: print('Something went wrong, the program wil quit') quit()
from ex117 import splitWords x = str(input('Enter a string:')) x = x.lower() list = splitWords(x) revlist = splitWords(x) revlist.reverse() a = False if list == revlist: a = True else: a = False print(a, revlist, list)