-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathod_counter.py
More file actions
112 lines (84 loc) · 3.37 KB
/
od_counter.py
File metadata and controls
112 lines (84 loc) · 3.37 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# import statements should generally be the very first line in a module
import re
# select a keyword (user input)
print("Welcome to the overdose counter.")
keyword = input("Which number would you like to search for? Please enter one digit, 1-7: ")
# while the keyword isn't a single word
while len(keyword.split()) > 1:
keyword = input("Please enter one digit, 1-7. For example, '3'.")
# load data
alcohol_files = {"Alcohol": "data/Alcohol.txt",
}
cocaine_files = {"Cocaine": "data/Cocaine.txt",
}
alprazolam_files = { "alprazolam": "data/alprazolam.txt",
}
heroin_files = {"Heroin": "data/Heroin.txt",
}
fentanyl_files = {"Fentanyl": "data/Fentanyl.txt",
}
# make the dictionary, using the filenames dictionary
alcohol = {}
for alcohol_file in alcohol_files:
fv = open(alcohol_files[alcohol_file])
alcohol[alcohol_file] = "".join(fv.readlines()).lower()
fv.close()
alprazolam = {}
for alprazolam_file in alprazolam_files:
fv = open(alprazolam_files[alprazolam_file])
alprazolam[alprazolam_file] = "".join(fv.readlines()).lower()
fv.close()
cocaine = {}
for cocaine_file in cocaine_files:
fv = open(cocaine_files[cocaine_file])
cocaine[cocaine_file] = "".join(fv.readlines()).lower()
fv.close()
heroin = {}
for heroin_file in heroin_files:
fv = open(heroin_files[heroin_file])
heroin[heroin_file] = "".join(fv.readlines()).lower()
fv.close()
fentanyl = {}
for fentanyl_file in fentanyl_files:
fv = open(fentanyl_files[fentanyl_file])
fentanyl[fentanyl_file] = "".join(fv.readlines()).lower()
fv.close()
# create a drug
drug_name1 = "alcohol"
drug1_ods = ""
for alcohol_ods in alcohol:
drug1_ods += alcohol[alcohol_ods]
alcohol_total= "84"
drug_name2 = "alprazolam"
drug2_ods = ""
for alprazolam_ods in alprazolam:
drug2_ods += alprazolam[alprazolam_ods]
alprazolam_total="68"
drug_name3 = "cocaine"
drug3_ods = ""
for cocaine_ods in cocaine:
drug3_ods += cocaine[cocaine_ods]
cocaine_total="145"
drug_name4 = "heroin"
drug4_ods = ""
for heroin_ods in heroin:
drug4_ods += heroin[heroin_ods]
heroin_total="206"
drug_name5 = "fentanyl"
drug5_ods = ""
for fentanyl_ods in fentanyl:
drug5_ods += fentanyl[fentanyl_ods]
fentanyl_total="235"
# count and print for drugs!
print("")
print("Within Allegheny County in 2016, there were %s drugs (including the main drug) combined in..." % (keyword))
alcohol_word_count = re.sub("[^\w]", " ", drug1_ods).split().count(keyword.lower())
print("%d out of %s total %s overdose%s." % (alcohol_word_count, alcohol_total, drug_name1, "" if (alcohol_word_count == 1) else "s"))
alprazolam_word_count = re.sub("[^\w]", " ", drug2_ods).split().count(keyword.lower())
print("%d out of %s total %s overdose%s." % (alprazolam_word_count, alprazolam_total, drug_name2, "" if (alprazolam_word_count == 1) else "s"))
cocaine_word_count = re.sub("[^\w]", " ", drug3_ods).split().count(keyword.lower())
print("%d out of %s total %s overdose%s." % (cocaine_word_count, cocaine_total, drug_name3, "" if (cocaine_word_count == 1) else "s"))
heroin_word_count = re.sub("[^\w]", " ", drug4_ods).split().count(keyword.lower())
print("%d out of %s total %s overdose%s." % (heroin_word_count, heroin_total, drug_name4, "" if (heroin_word_count == 1) else "s"))
fentanyl_word_count = re.sub("[^\w]", " ", drug5_ods).split().count(keyword.lower())
print("%d out of %s total %s overdose%s." % (fentanyl_word_count, fentanyl_total, drug_name5, "" if (fentanyl_word_count == 1) else "s"))