Thank you for visiting 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 is designed to guide you through key points and clear explanations related to the topic at hand. We aim to make your learning experience smooth, insightful, and informative. Dive in and discover the answers you're looking for!
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
Thank you for reading the article 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 information provided is useful and helps you understand this topic better. Feel free to explore more helpful content on our website!
- You are operating a recreational vessel less than 39 4 feet long on federally controlled waters Which of the following is a legal sound device
- Which step should a food worker complete to prevent cross contact when preparing and serving an allergen free meal A Clean and sanitize all surfaces
- For one month Siera calculated her hometown s average high temperature in degrees Fahrenheit She wants to convert that temperature from degrees Fahrenheit to degrees
Rewritten by : Jeany