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
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. Below is the code I have written, what I need it to hopefully output looks like starts with STUDY HOURS REPORT. That is what this snippet is supposed to display. Please go over and give me any comments on flow of code, execution, and validating please.
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. Please give me your suggestions on making it foolproof for the user (validations) and make sure that it flows properly. My code that i wrote is at the top, and what it is supposed to output is at the bottom. Please comment on and help me make sure I have it as good as possible.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
