Question
IN PYTHON (Class Average: Reading Student Records from a txt File). read the grades.txt file from the previous exercise. Display the data in tabular format.
IN PYTHON
(Class Average: Reading Student Records from a txt File). read the grades.txt file from the previous exercise. Display the data in tabular format.
previous exercise:
"""store a student name and their grades in three subject in a file"""
import os
try: # open a file with name grads with open("grades.txt", "w") as file: while True: # input student name first_name = input("Enter student's first name (or 'q' to quit): ") if first_name == 'q': break last_name = input("Enter student's last name: ") #input student grades try: test1 = int(input("Enter student's test 1 grade: ")) test2 = int(input("Enter student's test 2 grade: ")) test3 = int(input("Enter student's test 3 grade: ")) #remove error except ValueError: print("Invalid input. Please enter a numerical grade.") continue # Write student name and grade to file file.write(f"{first_name},{last_name},{test1},{test2},{test3} ")
except FileNotFoundError: print("File not found. Please check the file path and try again.") except: print("An error occurred. Please try again.")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started