Python Worksheet (2)
Python Worksheet (2)
WORKSHEET 1.1
1. Aim: Write a python code for schools grading system .the program needs to calculate the average
grade for each student from a list of students scores determines if each student has passed or failed
based on passing threshold.
2. Source Code:
def avg(scores):
return sum(scores) / len(scores)
def main():
num_students = int(input("Enter the number of students: "))
passing_threshold = float(input("Enter the passing threshold: "))
students = []
for i in range(num_students):
name = input(f"Enter the name of student {i+1}: ")
scores = [float(x) for x in input(f"Enter the scores of {name} : ").split()]
avg_score = avg(scores)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
print("\nStudent Grades:")
for student in students:
print("Name:", {student[0]})
print("Average Score:" ,{student[1]})
print("Grade:", {student[2]})
if _name_ == "_main_":
main()
3. Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes:
1. List Manipulation: Students will gain proficiency in working with lists, including creating
lists, iterating over them using loops, and extracting values from lists.
2. Basic Data Manipulation: Students will learn how to manipulate numerical data, such as
calculating averages and determining pass or fail statuses based on thresholds.
3. Functions: Students will learn how to define and use functions to encapsulate reusable
pieces of code, promoting modularity and readability.
4. Conditional Statements: Students will understand conditional statements (if and else) and
how they are used to make decisions based on certain conditions.