-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpractice.py
More file actions
31 lines (23 loc) · 898 Bytes
/
practice.py
File metadata and controls
31 lines (23 loc) · 898 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
# In this problem you will read from a file a list of comma separated integers
# A number can appear anywhere, any number of times
# The program:
# A user can search for any number
# You need to tell them where (starting at 1, not 0), and how many times the number occurs
######################################################
# Hi, Vincent. Please check if this is what you want the code to do ~ Saffa #
def read_file(files):
f = open(files, "r")
r = f.read()
z = []
for i in r.split():
z.append(i)
# print z
return z
def search(first, word):
print "The word you are searching for \"%s\" occurs %s times" % (word, first.count(word))
def main():
files = raw_input(" What is the name of your file: ")
read_file(files)
u_input = raw_input("What word are you searching for: ")
search(read_file(files), u_input)
main()