Last active
August 29, 2015 14:09
-
-
Save HoughIO/b05fb1fe98e21160e48a to your computer and use it in GitHub Desktop.
no idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Individual Lab 14 | |
def main(): | |
mydata = input("Filename? ") | |
try: | |
infile = open(mydata, "r") | |
except: | |
print("Can't open file") | |
return | |
print('File opened') | |
ctr = 0 | |
total = 0 | |
for line in infile: | |
avg = process(line) | |
total += avg | |
print(avg) | |
ctr +=1 | |
print("\nAverage over all students =", end=" ") | |
if total != 0: | |
print(total / ctr) | |
else: | |
print(0) | |
infile.close() | |
def process (line): | |
lst = line.split() | |
# first name, last name, 5 grades | |
tot = 0 | |
print(lst[0], lst[1], end=" ") | |
for i in range(2, 7): | |
gr = int(lst[i]) | |
tot += gr | |
return tot/5 | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment