Skip to content

german-boop/Student-Grades-Ranking-Tie-Aware-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊Student-Grades-Ranking-Tie-Aware-

A beginner-friendly Python script to rank students by grades with correct tie handling.

🎓 Student Grades Ranking (Tie-Aware)

A clean and beginner-friendly Python script that ranks students based on their grades, while correctly handling ties.
Students with the same grade receive the same rank, and ranking numbers are adjusted accordingly.

This project focuses on clarity, correctness, and PEP 8 compliance, making it ideal for Python learners and first-time contributors.

🎓📊🏆 Student Grades Ranking Project

🗂 Project Structure

📂 student-grades-ranking/
├── 📄 main.py
├── 📄 README.md
├── 📄 LICENSE
├── 📄 requirements.txt
├── 📄 .gitignore
└── 📂 .github/
    └── 📂 workflows/
        └── 📄 python-ci.yml


📄 File & Folder Explanation

🐍 main.py
* The main Python script
* Contains the student ranking logic with tie handling
* Fully PEP 8 compliant
* Run with:
bash
python main.py

📘 README.md
* Project documentation
* includes:
  * Project description
  * Example output
  * Ranking logic explanation
  * How to run
  * Contribution guide

📜 LICENSE
* Project license (MIT License)
* Users are allowed to use, modify, and distribute the code freely.

📦 requirements.txt
* Lists dependencies
* For this project (no external packages required)
* 
# No external dependencies

🚫 .gitignore

* Excludes unnecessary files from Git tracking:
# Byte-compiled files
__pycache__/
*.py[cod]

# Virtual environments
venv/
.venv/

# IDEs
.vscode/
.idea/

# OS files
.DS_Store
Thumbs.db


🤖 .github/workflows/python-ci.yml
* Automatic CI workflow for GitHub Actions:

# yaml
name: Python CI

on:
  push:
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install flake8

      - name: Lint with flake8
        run: |
          flake8 main.py


# 🐍 Python Code (PEP 8 Compliant)
# Dictionary with student grades
students = {
    "Ali": 18,
    "Sara": 20,
    "Reza": 16,
    "John": 19,
    "Lara": 20
}

# Sort students by grade in descending order
sorted_students = sorted(students.items(), key=lambda item: item[1], reverse=True)

print("Ranking of students by grade (ties handled):")

rank = 0          # Current rank to display
prev_grade = None # Previous student's grade
count = 0         # Number of students processed

for name, grade in sorted_students:
    count += 1
    # Update rank only when the grade changes
    if grade != prev_grade:
        rank = count

    print(f"{rank}. {name}: {grade}")
    prev_grade = grade


🖼 Example Output

Ranking of students by grade (ties handled):
1. Sara: 20
1. Lara: 20
3. John: 19
4. Ali: 18
5. Reza: 16

## ✨ Key Concepts Covered

- Using Python dictionaries to store structured data
- Sorting dictionary items by value in descending order
- Implementing ranking logic with tie handling
- Writing readable and maintainable Python code
- Following PEP 8 style guidelines


## 🧠 Ranking Logic Explained

1. Students are sorted by grade in descending order.
2. A counter tracks how many students have been processed.
3. The rank is updated **only when the grade changes**.
4. Students with the same grade receive the same rank.
5. The next rank skips positions correctly after ties.


## 🌱 Beginner Friendly

This repository is suitable for:
- Python beginners
- Learning sorting and ranking algorithms
- Understanding tie-aware ranking systems
- First open-source contributions
- Practice projects for clean code


About

A beginner-friendly Python script to rank students by grades with correct tie handling.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors

Languages