×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Student Letter Grade Assignment Solution using Python

July 09, 2024
Martin Jonas
Martin Jonas
🇦🇺 Australia
Python
Dr. Martin Jonas, PhD in Computer Science from Southern Cross University, Australia. With 4 years of experience in Python assignments, I offer expert guidance and support to help you excel in your programming projects.
Tip of the day
Ensure you understand the kinematics and dynamics principles governing robotic motion. Use flowcharts and diagrams to plan the system's behavior and debug efficiently. Document every step for clarity.
News
Stanford University has revamped its Code in Place course, emphasizing large-scale interactive programming education, while Coursera now offers specialized certificates in game design and mobile app development with integrated AI tools like Generative AI​

In this programming challenge, you will write a python assignment program to calculate and save/display student letter grades. Create a dictionary where the key is the name of a student and the value is a list of the student's grades. Drop the lowest grade from each student's grades. Display to the console AND write to a file a list of the student names and their corresponding letter grades: The letter grade should be calculated from the average of the student's grades (excluding the grade that was dropped):

Average 90-100: A

Average 80-89.99

Average 70-79.99: C

Average 60-69.99: D

Average below 60: F

Your program should work for data files with a varying number of students and varying numbers of grades per student. Example

David887590868094
Mary659892978685
Caitlin80848288860
Jonah757074838678
Rebecca55625006460

Output:

DavidB
MaryA
CaitlinB
JonahC
RebeccaF

Solution:

def calc_grade(marks): if marks >= 90: return 'A' elif marks >= 80: return 'B' elif marks >= 70: return 'C' elif marks >= 60: return 'D' return 'E' student = {} # Reading the data from text file with open('data.txt') as txt_file: data = txt_file.readlines() # Putting the data into dictionary for line in data: stud = line.split(' ') student[stud[0]] = [int(marks) for marks in stud[1:]] # Removing least grade of each student for stud in student: marks = student[stud] min_marks = min(marks) min_ind = student[stud].index(min_marks) del student[stud][min_ind] # Calculating Letter Grade of each student grades = {} for stud in student: total_marks = sum(student[stud]) / len(student[stud]) grade = calc_grade(total_marks) grades[stud] = grade # Printing calculated letter grades to the console for stud in grades: print(stud + '\t\t' + grades[stud]) # Writing the result out to a file with open('output.txt', mode='w') as txt_file: for stud in grades: txt_file.write(stud + '\t\t' + grades[stud] + '\n') Related Experts Josh, U Professional Python Homework helper Average rating on 412 reviews 4.9/5 Josh, U Austin, USA Bachelor’s Degree. in Programming, St. Edward’s University, USA 98.5% Success rate 2459 Completed orders 96 minutes Response time 21996 USD Earned Stacy L Python Homework Help Expert Average rating on 1249 reviews 4.8/5 Stacy L Houston, USA Masters in Programming, University of Houston 99.3% Success rate 5024 Completed orders 94 minutes Response time 22129 USD Earned Samuel, H Expert Python Homework helper Average rating on 360 reviews 4.8/5 Samuel, H Vancouver, Canada PhD. in Programming, University of Alberta, Canada 97% Success rate 1454 Completed orders 95 minutes Response time 21564 USD Earned Contact

Related Samples

At ProgrammingHomeworkHelp.com, we offer an extensive collection of related samples for Python assignments. Our expertly crafted samples cover various topics, including data analysis, machine learning, and web development, providing students with valuable insights and practical solutions. Our website is dedicated to supporting students in their academic journey by offering comprehensive assignment help and ensuring they grasp essential programming concepts. Visit ProgrammingHomeworkHelp.com to explore our Python samples and elevate your understanding of this versatile programming language.