Assignment Overview
In this assignment, you will build a Student Grade Analyzer and Course Registration System for a university. This comprehensive project requires you to apply ALL Module 3 concepts: conditionals (if, elif, else), loops (for, while), loop control (break, continue), list comprehensions, dictionary comprehensions, and nested control structures.
Conditionals (3.1)
If/elif/else, ternary operators, nested conditionals, and logical operators
Loops (3.2)
For loops, while loops, break, continue, enumerate, range, and zip
Advanced Flow (3.3)
List comprehensions, dictionary comprehensions, nested loops, and complex patterns
The Scenario
TechU University
You have been hired as a Python Developer at TechU University's Academic Department. The registrar's office needs a grade analysis and course registration system built using Python. The department head has given you this task:
"We have student grade data in Python lists and dictionaries. We need a system that can calculate grades, identify at-risk students, recommend courses based on prerequisites, generate statistics, and validate course registrations. The system must use conditionals to grade students, loops to process multiple students, and comprehensions to transform data efficiently. Can you build this for us?"
Your Task
Create a Python file called grade_analyzer.py that implements a complete
grade analysis and course registration system. Your code must process student data using
conditionals for grading logic, loops for data processing, and comprehensions for efficient
transformations.
The Dataset
You will work with student grade data structured as Python lists and dictionaries.
Copy this data structure exactly into your grade_analyzer.py file:
Student Data Structure
# Student grade data
students = [
{
"id": "S001",
"name": "Alice Johnson",
"year": 2,
"major": "Computer Science",
"grades": {"MATH101": 85, "CS101": 92, "ENG101": 78, "PHYS101": 88},
"attendance": 95,
"completed_courses": ["CS100", "MATH100", "ENG100"]
},
{
"id": "S002",
"name": "Bob Smith",
"year": 3,
"major": "Data Science",
"grades": {"MATH201": 76, "CS201": 82, "STAT201": 90, "CS202": 85},
"attendance": 88,
"completed_courses": ["CS100", "CS101", "MATH100", "MATH101", "STAT100"]
},
{
"id": "S003",
"name": "Carol Davis",
"year": 1,
"major": "Computer Science",
"grades": {"CS100": 95, "MATH100": 92, "ENG100": 88, "PHYS100": 90},
"attendance": 98,
"completed_courses": []
},
{
"id": "S004",
"name": "David Wilson",
"year": 2,
"major": "Computer Science",
"grades": {"MATH101": 58, "CS101": 62, "ENG101": 55, "PHYS101": 60},
"attendance": 72,
"completed_courses": ["CS100", "MATH100", "ENG100"]
},
{
"id": "S005",
"name": "Emma Brown",
"year": 3,
"major": "Data Science",
"grades": {"MATH201": 94, "CS201": 96, "STAT201": 98, "CS202": 95},
"attendance": 100,
"completed_courses": ["CS100", "CS101", "MATH100", "MATH101", "STAT100", "STAT101"]
},
{
"id": "S006",
"name": "Frank Miller",
"year": 1,
"major": "Computer Science",
"grades": {"CS100": 70, "MATH100": 68, "ENG100": 75, "PHYS100": 72},
"attendance": 85,
"completed_courses": []
},
{
"id": "S007",
"name": "Grace Lee",
"year": 2,
"major": "Data Science",
"grades": {"MATH101": 88, "CS101": 90, "STAT101": 92, "ENG101": 86},
"attendance": 93,
"completed_courses": ["CS100", "MATH100", "ENG100"]
},
{
"id": "S008",
"name": "Henry Taylor",
"year": 3,
"major": "Computer Science",
"grades": {"CS201": 45, "MATH201": 52, "CS202": 48, "PHYS201": 50},
"attendance": 65,
"completed_courses": ["CS100", "CS101", "MATH100", "MATH101"]
}
]
# Course prerequisites
course_prerequisites = {
"CS101": ["CS100"],
"CS201": ["CS100", "CS101"],
"CS202": ["CS101"],
"MATH101": ["MATH100"],
"MATH201": ["MATH100", "MATH101"],
"STAT101": ["MATH100"],
"STAT201": ["STAT100", "STAT101"],
"PHYS101": ["PHYS100", "MATH100"],
"PHYS201": ["PHYS100", "PHYS101"]
}
# Course catalog with difficulty levels
course_catalog = {
"CS100": {"name": "Intro to Programming", "credits": 4, "difficulty": "easy"},
"CS101": {"name": "Data Structures", "credits": 4, "difficulty": "medium"},
"CS201": {"name": "Algorithms", "credits": 4, "difficulty": "hard"},
"CS202": {"name": "Database Systems", "credits": 3, "difficulty": "medium"},
"MATH100": {"name": "Calculus I", "credits": 4, "difficulty": "medium"},
"MATH101": {"name": "Calculus II", "credits": 4, "difficulty": "medium"},
"MATH201": {"name": "Linear Algebra", "credits": 3, "difficulty": "hard"},
"STAT100": {"name": "Statistics Basics", "credits": 3, "difficulty": "easy"},
"STAT101": {"name": "Probability", "credits": 3, "difficulty": "medium"},
"STAT201": {"name": "Advanced Statistics", "credits": 4, "difficulty": "hard"}
}
Data Structure Explained
id- Unique student identifier (string)name- Student full name (string)year- Current academic year (integer: 1-4)major- Student's major program (string)grades- Dictionary mapping course codes to numeric grades (0-100)attendance- Attendance percentage (integer: 0-100)completed_courses- List of successfully completed course codes
Requirements
Your grade_analyzer.py must implement ALL of the following functions.
Each function demonstrates specific control flow concepts and will be tested individually.
Calculate Letter Grade (Conditionals)
Create a function get_letter_grade(score) that:
- Takes a numeric score (0-100) as input
- Uses if/elif/else to determine letter grade
- Returns: A+ (95-100), A (90-94), B+ (85-89), B (80-84), C+ (75-79), C (70-74), D (60-69), F (below 60)
- Must use elif chains (not multiple if statements)
def get_letter_grade(score):
\"\"\"Return letter grade based on numeric score using if/elif/else.\"\"\"
# Must use: if/elif/else chain
# Example: 92 returns \"A\", 78 returns \"C+\", 55 returns \"F\"
pass
Calculate GPA (Conditionals + Loops)
Create a function calculate_gpa(grades_dict) that:
- Takes a grades dictionary (course: score) as input
- Uses for loop to iterate through all grades
- Uses conditionals to convert each score to GPA points (A+=4.0, A=4.0, B+=3.5, B=3.0, C+=2.5, C=2.0, D=1.0, F=0.0)
- Returns the average GPA rounded to 2 decimal places
def calculate_gpa(grades_dict):
\"\"\"Calculate GPA from grades dictionary using loops and conditionals.\"\"\"
# Must use: for loop to iterate grades, if/elif/else for GPA conversion
# Example: {\"CS101\": 92, \"MATH101\": 85} returns 3.75
pass
Determine Academic Status (Nested Conditionals)
Create a function get_academic_status(gpa, attendance) that:
- Takes GPA (float) and attendance percentage (int) as inputs
- Uses nested if statements to determine status
- Returns: \"Dean's List\" (GPA >= 3.5 and attendance >= 90), \"Good Standing\" (GPA >= 2.0 and attendance >= 75), \"Probation\" (GPA < 2.0 or attendance < 75), \"Suspension\" (GPA < 1.0 or attendance < 60)
def get_academic_status(gpa, attendance):
\"\"\"Determine academic status using nested conditionals.\"\"\"
# Must use: nested if/else statements
# Check GPA first, then attendance within each GPA range
pass
Find At-Risk Students (Loops + Conditionals)
Create a function find_at_risk_students(students) that:
- Takes the students list as input
- Uses for loop to iterate through students
- Uses conditionals to identify at-risk students (GPA < 2.0 OR attendance < 75)
- Returns a list of tuples:
(student_id, name, gpa, attendance)
def find_at_risk_students(students):
\"\"\"Find students with GPA < 2.0 or attendance < 75.\"\"\"
# Must use: for loop, conditional checks, append to result list
# Call calculate_gpa() for each student
pass
Get Top Performers (List Comprehension)
Create a function get_top_performers(students, min_gpa=3.5) that:
- Takes students list and minimum GPA threshold as inputs
- Uses list comprehension with if condition
- Returns list of student names with GPA >= min_gpa
- Must be a single list comprehension (not a loop)
def get_top_performers(students, min_gpa=3.5):
\"\"\"Return names of students with GPA >= min_gpa using list comprehension.\"\"\"
# Must use: list comprehension with conditional
# Example: [name for student in students if ...]
pass
Get Course Statistics (Dictionary Comprehension)
Create a function get_course_statistics(students) that:
- Takes students list as input
- Uses loops and dictionary comprehension
- Returns dictionary mapping course codes to average grades
- First collect all grades per course using loops, then use dict comprehension for averages
def get_course_statistics(students):
\"\"\"Return dict with course codes as keys and average grades as values.\"\"\"
# Step 1: Use loops to collect all grades per course
# Step 2: Use dictionary comprehension to calculate averages
# Example: {\"CS101\": 85.5, \"MATH101\": 78.3, ...}
pass
Check Prerequisites (Loops + Conditionals)
Create a function can_enroll(student, course_code, prerequisites_dict) that:
- Takes student dict, course code, and prerequisites dictionary as inputs
- Uses for loop to check if all prerequisites are in student's completed courses
- Uses if/else to validate enrollment eligibility
- Returns
Trueif all prerequisites met,Falseotherwise
def can_enroll(student, course_code, prerequisites_dict):
\"\"\"Check if student has completed all prerequisites for a course.\"\"\"
# Must use: for loop to check each prerequisite
# Handle courses with no prerequisites (not in prerequisites_dict)
pass
Get Eligible Courses (Nested Loops)
Create a function get_eligible_courses(student, course_catalog, prerequisites_dict) that:
- Takes student dict, course catalog, and prerequisites as inputs
- Uses nested loops: outer loop through courses, inner loop to check prerequisites
- Returns list of course codes the student can enroll in
- Excludes courses already completed by the student
def get_eligible_courses(student, course_catalog, prerequisites_dict):
\"\"\"Return list of courses student is eligible to take.\"\"\"
# Must use: nested loops (course iteration and prerequisite checking)
# Filter out already completed courses
pass
Generate Grade Report (Loops + String Formatting)
Create a function generate_grade_report(student) that:
- Takes a student dictionary as input
- Uses for loop to iterate through student's grades
- Uses string formatting to create a formatted report
- Returns a multi-line string with student info, course grades, GPA, and status
def generate_grade_report(student):
\"\"\"Generate formatted grade report for a student.\"\"\"
# Format: Name, ID, Year, Major
# List each course with score and letter grade
# Show GPA and academic status
# Use for loop to iterate grades
pass
Filter by Major (List Comprehension)
Create a function filter_by_major(students, major) that:
- Takes students list and major name as inputs
- Uses list comprehension with condition
- Returns list of student dictionaries matching the major
- Must be a single-line list comprehension
def filter_by_major(students, major):
\"\"\"Return students in specified major using list comprehension.\"\"\"
# Must use: [student for student in students if ...]
pass
Count Students by Year (Dictionary Comprehension + Loops)
Create a function count_by_year(students) that:
- Takes students list as input
- Uses loops and conditionals to count students per year
- Uses dictionary comprehension or manual dict building
- Returns dictionary:
{1: count, 2: count, 3: count, 4: count}
def count_by_year(students):
\"\"\"Count number of students in each year (1-4).\"\"\"
# Initialize counts for years 1-4
# Use for loop to count students
# Return dictionary mapping year to count
pass
Search Student (While Loop + Break)
Create a function search_student_by_id(students, student_id) that:
- Takes students list and student ID as inputs
- Uses while loop with index to search
- Uses break to exit loop when found
- Returns student dictionary if found,
Noneif not found
def search_student_by_id(students, student_id):
\"\"\"Search for student by ID using while loop and break.\"\"\"
# Must use: while loop with index counter
# Use break when student found
pass
Print All Reports (For Loop + Continue)
Create a function print_all_reports(students, skip_year=None) that:
- Takes students list and optional year to skip
- Uses for loop to iterate through students
- Uses continue to skip students in specified year
- Prints grade report for each student (calls generate_grade_report)
- Returns count of reports printed
def print_all_reports(students, skip_year=None):
\"\"\"Print reports for all students, optionally skipping a year.\"\"\"
# Must use: for loop with continue statement
# If skip_year matches student year, use continue
# Print report and count printed reports
pass
Main Program
Create a main() function that:
- Demonstrates ALL previous functions with the student data
- Prints results in organized sections with clear headers
- Uses the
if __name__ == \"__main__\":pattern - Shows at least 2 examples per function
def main():
# Section 1: Individual student analysis
print(\"=== INDIVIDUAL STUDENT ANALYSIS ===\")
student = students[0]
print(f\"Student: {student['name']}\")
print(f\"Letter Grade for 92: {get_letter_grade(92)}\")
print(f\"GPA: {calculate_gpa(student['grades'])}\")
# ... more examples
# Section 2: Class-wide statistics
print(\"\\n=== CLASS STATISTICS ===\")
at_risk = find_at_risk_students(students)
print(f\"At-Risk Students: {len(at_risk)}\")
# ... more examples
# Section 3: Course enrollment
print(\"\\n=== COURSE ENROLLMENT ===\")
eligible = get_eligible_courses(students[0], course_catalog, course_prerequisites)
print(f\"Eligible courses: {eligible}\")
# ... more examples
# Section 4: Reports
print(\"\\n=== GRADE REPORTS ===\")
print_all_reports(students, skip_year=1)
if __name__ == \"__main__\":
main()
Submission
Create a public GitHub repository with the exact name shown below:
Required Repository Name
techu-grade-analyzer
Required Files
techu-grade-analyzer/
├── grade_analyzer.py # Your Python file with ALL 14 functions
├── sample_output.txt # Output from running your program
└── README.md # REQUIRED - see contents below
README.md Must Include:
- Your full name and submission date
- Brief description of your solution approach
- Which control flow concepts you used in each function
- Any challenges faced and how you solved them
- Instructions to run your program (
python grade_analyzer.py)
Do Include
- All 14 functions implemented and working
- Docstrings for every function
- Comments explaining control flow logic
- sample_output.txt from running main()
- Use of comprehensions where specified
- Proper if/elif/else, for, while, break, continue
- README.md with all required sections
Do Not Include
- External libraries (pure Python only)
- Any .pyc or __pycache__ files (use .gitignore)
- Code that doesn't run without errors
- Using loops where comprehensions required
- Using comprehensions where loops required
- Hardcoded outputs (functions must calculate)
grade_analyzer.py and verify all functions work correctly.
Save the console output to sample_output.txt.
Enter your GitHub username - we'll verify your repository automatically
Grading Rubric
Your assignment will be graded on the following criteria:
| Criteria | Points | Description |
|---|---|---|
| Conditionals (Functions 1, 2, 3) | 30 | Correct use of if/elif/else, nested conditionals, and logical operators |
| Loops (Functions 4, 8, 9, 13) | 35 | Proper use of for loops, while loops, nested loops, and iteration patterns |
| Loop Control (Functions 12, 13) | 20 | Effective use of break and continue statements |
| Comprehensions (Functions 5, 6, 10, 11) | 30 | Correct implementation of list and dictionary comprehensions with conditions |
| Logic & Algorithms | 20 | All functions produce correct results with proper logic |
| Code Quality | 15 | Docstrings, comments, naming conventions, and clean organization |
| Total | 150 |
Ready to Submit?
Make sure you have completed all requirements and reviewed the grading rubric above.
Submit Your AssignmentPro Tips
Control Flow Best Practices
- Use elif instead of multiple separate if statements
- Keep nested conditionals to max 2-3 levels deep
- Use break to exit loops early when condition met
- Use continue to skip current iteration efficiently
Comprehensions
- Use list comprehensions for simple transformations
- Keep comprehensions readable (not too complex)
- Use regular loops for complex multi-step logic
- Add conditions with if at the end of comprehension
Time Management
- Start with simple functions (1-3) before complex ones
- Test each function individually before moving on
- Use print statements to debug loop iterations
- Build main() incrementally as you complete functions
Common Mistakes
- Forgetting to return values from functions
- Using == instead of = for assignment
- Infinite while loops without proper exit condition
- Using loops when comprehensions are required