A small project that computes the score you need on a final exam to reach a target overall grade.
final_grade_calculator.py— the main Python program.- It can run as a command-line calculator.
- It can also start a Flask web server that serves the HTML interface and calculates results via a JSON API.
index.html— the web UI for the calculator.- It contains the form, validation, and result display.
- It sends the input values to the Python backend at
/calculate.
The calculator uses this formula:
desired = current * (1 - w) + final_score * w
Where:
currentis your current grade percentage.wis the final exam weight as a decimal (final weight % / 100).desiredis the overall grade percentage you want.
Solving for final_score gives:
final_score = (desired - current * (1 - w)) / w
If the result is negative, that means your current grade is already high enough to reach the desired grade even if you score 0 on the final.
python final_grade_calculator.pyThen enter:
- Current grade (%)
- Final exam weight (%)
- Desired final grade (%)
The script will print the percent you need on the final.
python final_grade_calculator.py --webThen open your browser at:
http://127.0.0.1:5000
The web page will show a form with three inputs and a calculate button.
The web UI in index.html does not compute the final score entirely in the browser.
Instead, it sends the values to the backend with a POST request to /calculate.
The backend validates the inputs, performs the same grade calculation, and returns the needed score.
- Current grade:
0to200 - Final exam weight:
1to100 - Desired grade:
0to200
If the browser cannot reach the server, the page shows an error message telling you the Python server may not be running.
- The Python backend and the web UI share the same calculation logic via the
/calculateendpoint. - The HTML page is not a standalone static calculator in this repository because it depends on the Flask backend to return results.