Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request
- app = Flask(__name__)
- #serve up the main page (index)
- @app.route("/")
- def index():
- return render_template("index.html")
- #process form submit data and give results HTML page
- @app.route("/convert")
- def convert():
- #get info from the submitted form
- fname = request.args['firstname']
- lname = request.args['lastname']
- dollars = request.args['dollars']
- #cents = request.args['cents']
- history = request.args['history']
- math = request.args['math']
- english = request.args['english']
- science = request.args['science']
- lang = request.args['lang']
- #do the conversion calc (100 -> 4.0)
- avg = (int(history) + int(math) + int(english) + int(science) + int(lang)) / 5
- if avg > 97:
- gpa = 4.3
- elif avg > 93:
- gpa = 4.0
- elif avg > 90:
- gpa = 3.7
- elif avg > 87:
- gpa = 3.3
- else:
- gpa = 2.0
- #bribe. .1 for every $5
- if dollars != "":
- bump = (int(dollars) / 5) * .1
- gpa += bump
- gpa = round(gpa,2)
- #build the results HTML page
- html = '<html><body>'
- html = html + '<table>'
- html = html + '<tr><th>Course</th><th>Grade</th></tr>'
- html = html + '<tr><td>History</td><td>' + str(history) + '</td></tr>'
- html = html + '<tr><td>Math</td><td>' + str(math) + '</td></tr>'
- html = html + '<tr><td>English</td><td>' + str(english) + '</td></tr>'
- html = html + '<tr><td>Science</td><td>' + str(science) + '</td></tr>'
- html = html + '<tr><td>Language</td><td>' + str(lang) + '</td></tr>'
- html = html + '</table>'
- html= html + '<br>Your 4.0 scaled GPA is ' + str(gpa)
- html = html + '</body></html>'
- return html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement