ssoni

GPA Calc (Flask/Python)

Apr 14th, 2021
333
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from flask import Flask, render_template, request
  2.  
  3. app = Flask(__name__)
  4.  
  5. #serve up the main page  (index)
  6. @app.route("/")
  7.  
  8. def index():
  9.     return render_template("index.html")
  10.  
  11. #process form submit data and give results HTML page
  12. @app.route("/convert")
  13.  
  14. def convert():
  15.  
  16.     #get info from the submitted form
  17.     fname = request.args['firstname']
  18.     lname = request.args['lastname']
  19.     dollars = request.args['dollars']
  20.     #cents = request.args['cents']
  21.     history = request.args['history']
  22.     math = request.args['math']
  23.     english = request.args['english']
  24.     science = request.args['science']
  25.     lang = request.args['lang']
  26.  
  27.     #do the conversion calc (100 -> 4.0)
  28.     avg = (int(history) + int(math) + int(english) + int(science) + int(lang)) / 5
  29.  
  30.     if avg > 97:
  31.         gpa = 4.3
  32.     elif avg > 93:
  33.         gpa = 4.0
  34.     elif avg > 90:
  35.         gpa = 3.7
  36.     elif avg > 87:
  37.         gpa = 3.3
  38.     else:
  39.         gpa = 2.0
  40.  
  41.     #bribe.  .1 for every $5
  42.     if dollars != "":
  43.         bump = (int(dollars) / 5) * .1
  44.         gpa += bump
  45.  
  46.     gpa = round(gpa,2)
  47.  
  48.     #build the results HTML page
  49.     html = '<html><body>'
  50.     html = html + '<table>'
  51.     html = html + '<tr><th>Course</th><th>Grade</th></tr>'
  52.     html = html + '<tr><td>History</td><td>' + str(history) + '</td></tr>'
  53.     html = html + '<tr><td>Math</td><td>' + str(math) + '</td></tr>'
  54.     html = html + '<tr><td>English</td><td>' + str(english) + '</td></tr>'
  55.     html = html + '<tr><td>Science</td><td>' + str(science) + '</td></tr>'
  56.     html = html + '<tr><td>Language</td><td>' + str(lang) + '</td></tr>'
  57.     html = html + '</table>'
  58.     html= html + '<br>Your 4.0 scaled GPA is ' + str(gpa)
  59.     html = html + '</body></html>'
  60.  
  61.     return html
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×