We appreciate your visit to Task Write a Python program to ensure data integrity for a student grading system Background In the galactic year 62 53 Cruz Space Synergy Industries. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
Answer :
If the file name is invalid, you will have three attempts to enter a valid file name before the program quits.
Here's a Python program that implements the requirements you mentioned:
```python
import os
def validate_file_name(file_name):
return os.path.isfile(file_name)
def read_student_data(file_name):
students = {}
current_student = None
with open(file_name, 'r') as file:
for line in file:
line = line.strip()
if line.startswith('Student'):
student_name = line.split(' ')[1]
current_student = student_name
students[current_student] = []
else:
grade = float(line)
students[current_student].append(grade)
return students
def calculate_average(grades):
return sum(grades) / len(grades)
def display_student_data(students):
for student, grades in students.items():
grade_average = calculate_average(grades)
grade_list = ' '.join(str(grade) for grade in grades)
print(f"{student} {grade_list} {grade_average}")
def main():
attempts = 0
while attempts < 3:
file_name = input("Enter the input file name: ")
if validate_file_name(file_name):
students = read_student_data(file_name)
display_student_data(students)
break
else:
print("Invalid file name. Please try again.")
attempts += 1
if attempts == 3:
print("Exceeded maximum number of attempts. Exiting program.")
if __name__ == '__main__':
main()
```
Make sure to save the above code in a `.py` file, such as `assignment4.py`. When you run the program, it will ask you to enter the input file name. If you enter a valid file name (an existing file), it will read the student information from the file, display each student's grades along with the average. If the file name is invalid, you will have three attempts to enter a valid file name before the program quits.
Note: Please replace the necessary information in the header of the program before submitting it.
To know more about Programming related question visit:
https://brainly.com/question/14368396
#SPJ11
Thanks for taking the time to read Task Write a Python program to ensure data integrity for a student grading system Background In the galactic year 62 53 Cruz Space Synergy Industries. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada