ssoni

GPA converter (Flask/Python)

Apr 9th, 2021 (edited)
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  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. #build the results HTML page
  42. return "Your GPA is " + str(gpa)
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
Add Comment
Please, Sign In to add comment