###################################################################### ## author: John Jiang ## How to use: ## Run the script in the same location as the file "results.txt" ## Place your results inside the file in the following format: ## Course Code Credit Mark ## e.g. ## COMP 1337 6 100 ## DOTA 1001 6 87 ## etc... ###################################################################### file = open("results.txt", 'rU') total_mark = 0 total_weight = 0 for line in file: words = line.split() weight = int(words[1][0]) * int(words[2]) mark = float(words[3]) total_mark += mark * weight total_weight += weight print "Wam:", total_mark/total_weight