Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- coding: utf-8 -*-
def clean(li):
return map(float, li)
def avg(li):
return sum(clean(li)) / len(li)
def main():
with open('./in.txt', 'r') as input_file, \
open('./out.txt', 'w') as output_file:
output_file.write('ID\tName\tSum\tAvg\n')
line = input_file.readline()
while line:
num, name, chinese, english, math = line.split()
li = clean([chinese, english, math])
output_file.write('%s\t%s\t%s\t%s\n'
% (num, name, sum(li), avg(li)))
line = input_file.readline()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.