Skip to content

Add Percentage Calculator with Input Validation#7

Open
abhiram-kadarla wants to merge 1 commit intomuskankhedia:mainfrom
abhiram-kadarla:add-percentage-calculator
Open

Add Percentage Calculator with Input Validation#7
abhiram-kadarla wants to merge 1 commit intomuskankhedia:mainfrom
abhiram-kadarla:add-percentage-calculator

Conversation

@abhiram-kadarla
Copy link

📌 Overview
This pull request introduces a new utility module percentage_calculator.py to the Student Utility Library.
The module provides a reusable function to calculate percentage based on total marks and obtained marks, including proper input validation and formatted output.

Features Implemented

  1. Calculates percentage using the formula:
    (obtained_marks / total_marks) × 100
  2. Rounds the result to 2 decimal places
  3. Validates input values:
  4. Raises ValueError if total marks are less than or equal to zero
  5. Raises ValueError if obtained marks are negative
  6. Includes a test execution block using if name == "main"

Example
Input:
Total Marks: 500
Obtained Marks: 420
Output:
Percentage: 84.00

FILE ADDED:
percentage_calculator.py.

Purpose of This Change
This utility enhances the Student Utility Library by providing a reliable and reusable percentage calculation function. It can be integrated into grading systems, academic tools, or other student-related modules in the future.

Testing:

The functionality was tested locally using sample inputs and verified for:
Correct percentage calculation
Proper rounding
Error handling for invalid inputs

Copy link
Owner

@muskankhedia muskankhedia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement for an existing function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants