Skip to main content

Building a Student Ranking System in Python: A Hands-On Guide to Sorting and File Handling

 



Code.... 





 Building a Student Ranking System in Python..

                  Have you ever wondered how teachers can quickly arrange students’ marks into a ranking list? Instead of doing it manually, we can use Python programming to make this task super easy.


Take student names and marks as input.

Sort students in descending order (highest marks first).

Display the rankings.`    

Save the results into a text file.


Step 1: Collect Student Data..

We start by asking the user how many students are in the class. Then, we take the name and marks of each student.




Here, we store each student’s name and marks as a tuple inside a list. Example:

[("Alice", 90), ("Bob", 85)].

Step 2: Sort Students by Marks

Now that we have the data, we need to sort it based on marks in descending order (highest to lowest).







* Lambda x: x[1] means we are sorting by the second element in the tuple (the marks).

*  Reverse=True ensures highest marks come first.

*  The sorted() function arranges the students based on marks.

 Step 3: Display the Rankings..

After sorting, we print the rankings on the screen.




 Step 4: Save Rankings to a File

Finally, we save the results into a file called class_rankings.txt.




Final Program Output....





Comments

Popular Posts

A beginner's guide to HTTP/1 vs. HTTP/2

HTTP, is a foundational protocol for communication on the World Wide Web. It defines how messages are formatted and transmitted between web clients and web servers, enabling the retrieval of web pages, images, videos, and other resources. Essentially, it's the language that web browsers and servers use to "talk" to each other.  What is HTTP? The Postman Analogy HTTP, or Hyper Text Transfer Protocol , is the fundamental set of rules that allows your web browser and a website's server to "talk" to each other. Think of it like this: You are the person who wants a package.   The Postman is your web browser. The Store is the website’s server (e.g., google.com ). When you want to visit a website, your browser uses HTTP to tell the server what you want. The server then finds the information and sends it back to your browser, which displays it for you. HTTP/1 The first major version of the Hyper Text Transfer Protocol , which is the basic system that web browsers...

From Code to Cloud - Understanding Hosting 🌐

Hosting (or Web Hosting) is a service that allows individuals or organizations to store their website files (HTML, CSS, images, videos, etc.) on a server connected to the internet so that anyone in the world can access the website via a domain name (like www.google.com).  Ever wondered how a website like youtube.com stays online 24/7 for anyone in the world to visit? The answer is hosting . It’s the essential service that makes your website visible on the internet and accessible to everyone, everywhere.  To understand it, let’s use a simple and relatable analogy: building and living in a house. The Landlord, the Land, and the House   Imagine your website is a house you want to build and open for visitors. The Website is the House: Your website is a collection of all its different parts. The front door is your homepage, the rooms are the other pages, and the furniture, decor, and art are all the files that give your site its look and feel. These are files like index....

Top 3 GitHub Features Every Beginner Should Master

Introduction If you’re just starting your journey as a developer, GitHub can feel a bit overwhelming. It’s packed with tools that professionals use every day but which ones should you focus on first? You don’t need to learn everything at once. Instead, start with the features that will give you the biggest benefits right away: safety, organization, and automation. Here are my top 3 GitHub features that every beginner should master and exactly why they matter. 1. Branches & Pull Requests Branches let you create  a copy of your project to try out new changes without ever touching the main, working code. It's like having a clone of your project where you can experiment freely.  Pull Requests   are how you propose merging those new changes back into the main project. They serve as a formal request to "pull" your changes from your branch into the main one, often after a review process. Benefits : You can experiment without fear of "breaking"...