#sdpsgssolutions #Friendlist - 0% #Starter Problems 3 # Open the input and output files. inputFile = open("listin.txt", "r") outputFile = open("listout.txt", "w") # Read how many numbers there will be myInput = inputFile.readline() n = int(myInput) # Reads the integers listPosition = 1 friendArray = [] positionList = [] while listPosition <= n: myInput = inputFile.readline().split() a = int(myInput[0]) b = int(myInput[1]) friendArray.append(a) friendArray.append(b) listPosition = listPosition + 1 outputFile.write(str(friendArray)+'\n') hits = [] for item in friendArray: tally = friendArray.count(item) #Makes an entry that is the number of hits paired with the relevant number values = (tally, item) # Only add one entry for each number in the set if values not in hits: hits.append(values) hits.sort(reverse=True) outputFile.write(str(hits)+'\n') if hits[0][0] > hits[1][0]: outputFile.write(str(hits[0][1])) elif hits[0][0] == hits[1][0] and hits[1][0] > hits[2][0]: outputFile.write(str(hits[0][1])+' '+str(hits[1][1])) else: outputFile.write("There is not a mode") # Finally, close the input/output files. inputFile.close() outputFile.close()