Write code using at least two functions: one to print the student's last name and another to calculate and display the percentage. If the grade is above 90, print "Excellent." For grades above 80, print "Well Done." Print "Good" for grades above 70, "Needs Improvement" for grades 60 or higher, and "Fail" for grades below 50. The main function should read the input file and pass the relevant arguments to the functions.

Answered on

 Here is a sample Python program that accomplishes what you're asking for:

```python def print_last_name(last_name): print("Student's Last Name:", last_name)

def calculate_and_display_percentage(score): percentage = (score / 100) * 100 print(f"Percentage: {percentage}%") # Determine the performance message based on the score if percentage > 90: print("Excellent.") elif percentage > 80: print("Well Done.") elif percentage > 70: print("Good.") elif percentage >= 60: print("Needs Improvement.") elif percentage < 50: print("Fail.")

def main(): # Assume 'student_data.txt' contains one line with the format: last_name, score with open('student_data.txt', 'r') as file: line = file.readline() last_name, score = line.strip().split(',') score = float(score) # Convert the score to a float print_last_name(last_name) calculate_and_display_percentage(score)

# Call the main function to execute the program if __name__ == "__main__": main() ```

Make sure you have an input file named `student_data.txt` in the same directory with content in the format `LastName,Score`. For example, the content could be `Doe,85`.

Related Questions