-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTownFunction.py
More file actions
46 lines (28 loc) · 762 Bytes
/
TownFunction.py
File metadata and controls
46 lines (28 loc) · 762 Bytes
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
#Hometown Generator by Mike Bradley
import sys
import os
import csv
import random
__location__ = os.path.dirname(os.path.abspath(sys.argv[0]))
f = open(os.path.join(__location__, 'data/Towns.csv'),'rU')
reader = csv.reader(f)
towns = []
for line in reader:
towns.append(line)
f.close()
total = 0
for item in towns:
item.append(item[1])
total += int(item[1])
item[1] = total
def TownFunc():
townNum = random.randint(0,int(towns[int(len(towns))-1][1]))
town = towns[0][0]
state = towns[0][2]
for x in range(len(towns)):
if int(towns[x][1])<= townNum:
town = towns[x][0]
state = towns[x][2]
population = towns[x][3]
reString = town + ", " + state + "; Population:" + population
return(reString)