Skip to content

Instantly share code, notes, and snippets.

@davegotz
Created April 23, 2019 15:02
Show Gist options
  • Select an option

  • Save davegotz/5bc4b241099fd1474abeabbc6e33b80e to your computer and use it in GitHub Desktop.

Select an option

Save davegotz/5bc4b241099fd1474abeabbc6e33b80e to your computer and use it in GitHub Desktop.
__author__ = 'David Gotz, [email protected], Onyen = gotz'
from flask import Flask
from flask import request
# Create the web application object.
app = Flask(__name__)
# Define the web pages.
@app.route("/index.html")
@app.route("/")
def index():
return """
<html><body>
<form method='get' action='/tips'>
Bill Amount: <input id="bill" value="0" name="bill" size='50'/>
<input type='submit' value='Submit' />
</form></body>
</html>"""
@app.route("/tips")
def tips():
bill = request.args.get('bill')
try:
bill_amount = float(bill)
return "You entered $"+format(bill_amount,".2f") \
+ "<p/>" \
+ "A 10% tip would be $"+format(0.1*bill_amount,",.2f") + "<br/>" \
+ "A 15% tip would be $"+format(0.15*bill_amount,",.2f") + "<br/>" \
+ "A 18% tip would be $"+format(0.18*bill_amount,",.2f") + "<br/>" \
+ "A 20% tip would be $"+format(0.2*bill_amount,",.2f") + "<br/>" \
+ "<p/><a href='/'>Click here to try again</a>."
except:
return "Please enter a numerical amount for the bill." + "<p/><a href='/'>Click here to try again</a>."
# Run the app.
#app.run()
app.run(host='0.0.0.0', port=1234)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment