def display_averages_and_totals(self): try: with open ("HowManyHours.txt", "r") as file:#read data from file data = file.readlines() total_credits = 0 total_study_hours = 0 except FileNotFoundError: print("HowManyHours.txt is not found.") for student in self.students: total_credits += student.credits total_study_hours += student.study_hours average_credits = total_credits/ len(self.students) average_study_hours = total_study_hours/ len(self.students) print("Study Hours Report") print(f"Created for{self.report_for},{self.report_employee_id}") print(f"Department:{self.report_department}") print(f"Created By: {self.creator},{self.employee_id}") print(f"Department:{self.department}}") print(f"Total Students: {len(self.students)}") print(f"Average Credits: {average_credits:.2f}") print(f"Average Study Hours: {average_study_hours:.2f}")       for line in data:#loop through each line in file values = line.strip().split("")#split line into list of values student = values[0] total_credits = values[1] study_hours = values[2] grade = [3] total_students += 1 total_credits += credits total_study_hours += study_hours average_credits = total_credits / total_students average_study_hours = total_study_hours / total_students #displaying the report    print("Total Students:", total_students) print("Average Credits:", average_credits) print("Average Study Hours:", average_study_hours) This is the code I have for an option in a menu driven program I am building. I will post what the output is supposed to look like a little further down. This is the last menu option in the program. We will need to open HowManyHours.txt and read all of the files (this file has been appended to quite a few times during the previous options in the program. It will tally up the total students that used the program, average the study hours of all the students who used the program, and will average up the credits taken by all students who used the program. This last menu option will display a report in the following format:   STUDY HOURS REPORT Created for Dr. Payne, A004567893 Dept: Computer Science Created By: Karen Smith, A00494928 Dept: Advising Total Students: 3 Average Credits: 9.00 Average Study Hours: 20.00

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

PLEASE GIVE ME THE ANSWER IN PYTHON language, please. I have asked for that in the last 3 questions and they answer in a different incorrect language. I apologize for starting off like that but could you please help me with the below.

def display_averages_and_totals(self):
try:
with open ("HowManyHours.txt", "r") as file:#read data from file
data = file.readlines()
total_credits = 0
total_study_hours = 0
except FileNotFoundError:
print("HowManyHours.txt is not found.")

for student in self.students:
total_credits += student.credits
total_study_hours += student.study_hours
average_credits = total_credits/ len(self.students)
average_study_hours = total_study_hours/ len(self.students)

print("Study Hours Report")
print(f"Created for{self.report_for},{self.report_employee_id}")
print(f"Department:{self.report_department}")
print(f"Created By: {self.creator},{self.employee_id}")
print(f"Department:{self.department}}")
print(f"Total Students: {len(self.students)}")
print(f"Average Credits: {average_credits:.2f}")
print(f"Average Study Hours: {average_study_hours:.2f}")
  
  
for line in data:#loop through each line in file
values = line.strip().split("")#split line into list of values
student = values[0]
total_credits = values[1]
study_hours = values[2]
grade = [3]

total_students += 1
total_credits += credits
total_study_hours += study_hours

average_credits = total_credits / total_students
average_study_hours = total_study_hours / total_students

#displaying the report
  
print("Total Students:", total_students)
print("Average Credits:", average_credits)
print("Average Study Hours:", average_study_hours)


This is the code I have for an option in a menu driven program I am building. I will post what the output is supposed to look like a little further down. This is the last menu option in the program. We will need to open HowManyHours.txt and read all of the files (this file has been appended to quite a few times during the previous options in the program. It will tally up the total students that used the program, average the study hours of all the students who used the program, and will average up the credits taken by all students who used the program.

This last menu option will display a report in the following format:

 

STUDY HOURS REPORT
Created for Dr. Payne, A004567893
Dept: Computer Science

Created By: Karen Smith, A00494928
Dept: Advising

Total Students: 3
Average Credits: 9.00
Average Study Hours: 20.00

 

-----I THINK MY CODE IS PRETTY DARN CLOSE BUT PLEASE HELP ME MAKE SURE it is going to output the above.

 
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education