-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw1.py
54 lines (38 loc) · 967 Bytes
/
hw1.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
def main():
filename = "intdata.txt"
file2 = "data2D.txt"
f = open(filename, "r")
count = 0
total = 0
thislist = []
for x in f:
count += 1
total += int(x)
thislist.append(int(x))
print("Total is " + str(total))
print("Count is " + str(count))
print("Average is " + str((total / count)))
f.close()
total = 0
count = 0
print("\n")
with open(file2) as fp:
cnt = 1
for line in fp:
print("Line {} : {} ".format(cnt,line))
line = line.strip().split(' ')
tootal(line)
cnt += 1
def tootal(*liss):
ttal = 0
for x in liss:
ct = 0
for y in x:
ttal += int(y)
ct += 1
print("\tTotal is " + str(ttal))
print("\tCount is " + str(ct))
print("\tAverage is " + str((ttal / ct)))
# print('\n')
if __name__ == '__main__':
main()