Respuesta :
Answer:
filename = input("Enter input file? ")
with open(filename, 'r') as data:
num_groups = []
num_counts = []
for line in data:
cols = line.split()
num_groups.append(int(cols[0]))
num_counts.append(int(cols[1]))
print("The number of num_groups in the file is "+str(len(num_groups)))
c_even = 0; c_odd = 0; s_odd = 0; s_even = 0
for i in num_counts:
if i%2 == 0:
c_even=c_even+1
s_even = s_even + i
else:
c_odd=c_odd+1
s_odd = s_odd + i
print("There are "+str(c_odd)+" odd student and "+str(c_even)+" even student")
print("The sum of odd student is "+str(s_odd))
print("The sum of even student is "+str(s_even))
print("The sum of all student is "+str(s_even+s_odd))
max_count = num_groups[num_counts.index(max(num_counts))]
print("The group number of the largest student is "+str(max_count))
min_count = num_groups[num_counts.index(min(num_counts))]
print("The group number of the smallest student is "+str(min_count))
print("The average of "+str(max(num_counts))+" and "+str(min(num_counts))+" is:",end=" ")
print("%.2f" % ((max(num_counts)+min(num_counts))*0.5))
bigkount = str(max(num_counts))
bigsum = 0
for i in range(len(bigkount)):
bigsum += int(bigkount[i])
print("The sum of all the digits in the largest student is: "+str(bigsum))
Explanation:
The program was written in Python.
Because of the length, I added an attachment where I used comments to explain the lines of the code