-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMale&FemaleEntries.py
68 lines (46 loc) · 1.9 KB
/
Male&FemaleEntries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Sean McGeachie
maleNames = ['Baptista','Petruchio','Gremio','Hortensio','Lucentio','Vincentio',
'Tranio','Biondello','Grumio','Curtis','Nathaniel','Phillip',
'Joseph','Nicholas','Peter', 'Tailor', 'Haberdasher','Officer']
femaleNames = ['KATHERINE','BIANCA', 'widow']
filePath = r"C:\Users\Sean\OneDrive\Documents\Uni\CS108\Plays\FolgerDigitalTexts_TXT_Complete\Shr.txt"
#read play into String array
global playArray
playArray = []
#this will need to be the directory where you keep .txt of play
with open(filePath) as myFile:
for line in myFile:
playArray.append(line)
#function will return the number of male lines
def findMaleLines():
maleLines = 0
maleLen = len(maleNames)
for line in playArray: #loop through every line in play
for i in range(maleLen): #loop through maleNames array
if maleNames[i].upper() in line:
maleLines += 1
return maleLines
#function will return number of female lines
def findFemaleLines():
femaleLines = 0
femaleLen = len(femaleNames)
for line in playArray: #loop through every line in play
for i in range(femaleLen): #loop through femaleNames array
if femaleNames[i].upper() in line:
femaleLines += 1
return femaleLines
maleLines = findMaleLines()
femaleLines = findFemaleLines()
print("female lines: " + str(femaleLines))
print("male lines: " + str(maleLines))
#plot graph
import matplotlib.pyplot as plt
def plotBarGraph(x, y):
plt.bar(x,y)
plt.title("Number of Male vs Female Lines")
plotBarGraph(["Male Lines (" + str(maleLines) + ")" ,"Female Lines (" + str(femaleLines) + ")"],[maleLines,femaleLines])
plt.savefig(filePath + 'male_vs_female_lines.pdf')
#x = [1,2]
#y = [femaleLines, maleLines]
#plt.bar(x,y)
#plt.show()