-
Notifications
You must be signed in to change notification settings - Fork 0
/
filespractice.py
52 lines (50 loc) · 982 Bytes
/
filespractice.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
"""
Practice on files for finals
"""
# Reading a file using for method
myFile = open("shopping.txt", 'r')
for line in myFile:
line = myFile.read()
print(line)
# # Reading a file using while loop
# myFile = open("shopping.txt", 'r')
# while True:
# line = myFile.readline()
# if line == '':
# break
# print(line[:-1])
#
# #Counting the number of words
# myFile = open('shopping.txt', 'r')
# wordCount = 0
#
# for line in myFile:
# wordCount += len(line.split())
# print(wordCount)
#
# # Counting four letter words
# twoFile = open('lorem.txt', 'r')
# wordCounter = 0
# for line in twoFile:
# words = line.split()
# for word in words:
# if len(word) == 4:
# wordCounter += 1
# print(wordCounter)
#
# #Averaging intergers from a file
# threeFile = open('intergers.txt', 'r')
# count = 0
#
# for line in threeFile:
# line = int(line.strip())
# numbers = int(line)
#
# count += numbers
# average = count//line
#
# print("The avaerage is", average)
#
#
#
#