Please read this lab exercise thoroughly, before attempting to write the program.

Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and:

Displays the number of groups in the file (5 %)
Displays the number of even and odd student count (5%)
Displays the sum of the even student count and the sum of the odd student count as well as the sum of all the student count (5%)
Displays the group numbers of the largest student count and the smallest student count (5 %)
Computes the average of the largest and smallest student count (10 %)
Compute the sum of ALL the digits in the largest student count (i.e. 952 – Sum is 9+5+2 = 16) (15 %)
Assume the contents of the file are as follows but that the pairs of data can change later:

1 25

2 123

3 475

4 61

5 77

6 910

7 234

8 138

9 134

10 95

11 674

12 345

13 31

14 211

15 952

16 873

17 22

18 7

19 876

20 347

21 450

The following is a sample output: User input in red

What is name of the input file? integers.dat

The number of groups in the file is 21

There are 12 odd student count and 9 even student count

The sum of the odd student count is 2645

The sum of the even student count is 4390

The sum of all the student count is 7035

The group number of the largest student count is 15

The group number of the smallest student count is 18

The average of 952 and 7 is 479.5

The sum of all the digits in the largest student count is 16

NOTE:

Use two decimal point precision for the average
To check your code, adjust one of the student count in the file, recompile your code and run again (suggest changing the largest or smallest student count )
Even though there are 21 pairs of numbers in the file, the program should NOT presume there will always be 21 pairs of numbers. In other words, you should not solve this problem by declaring 21 pairs of values. If I choose to use another integers.dat file other than the one provided with the assignment, your program should still work correctly with that file as well. All you can assume is that a series of integers will be read in from the file. Therefore, you need to implement a solution that uses the repetition control structures (for, while, do…while) in the reading and processing of these values to produce your output.

Answers

Answer 1

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


Related Questions

Other Questions
The ideological war between the Communist East and the Democratic West is known as the- A. Political War B. Hot War C. Ideological War D. Cold War Which one is the correct answer please It is formed as a result of long continued weathering process of rocks Is this statement always true?A cross section parallel to the base of a right rectangular prism is a square What is the domain? {-2,3); (1,4); (2,4); (0,0)} What is this trying to ask me ??? Solve the propotionq/5 = 4/1 help plsss(+Brainliest too.)Here is a picture of a cube, and the net of this cube.What is the surface area of this cube? Working for commission can be considered a blessing and a curse for an artist. How might it be interpreted to be a good thing for an artist? (I'll give brainliest please help!)A. The artist has no one to consult with during the process.B. The artist must create whatever art they are told to create.C. The artist will get paid for the completed work.D. The artist will never get to share the completed work with anyone. Spanish please help !Completa estas conversaciones con la forma correcta del pretrito de ser o ir. Indica el infinitivo de cada forma verbal. Sigue el mode What does theme add to a story? *( A) A sense of location.(B ) Motivation for the characters.(C) Dialogue for the characters.(D )An important message. which of the following is not a function of the skeleton yes or no ? i need help please help me with this i need it 2x+3y=5-y missing value Why was it difficult to have accurate time in the Middle Ages? A: The clocks were sundials.B: There were no clocks.C: The people didn't understand time.D: Time was not important to the people. Bonjour mon exercice c'est 36%de 25km. C'est un exercice de maths faire pouvez vous m'expliquer svp merci The rectangle shown below has a diagonal of 15 cm and a width of 7 cm. To the nearest centimeter, what is the length, x, of the rectangle? Round your answer to the nearest tenth. 15 7 X Help..!! Right answers will be marked as brainliest..! Answer all the questions..! Help me out here pleaseeeeeeeeeeeeeee