External Exam Download Resources Web Applications Games Recycle Bin

Output questions

  1. Create a flask app that says "G'DAY MATE!" on launch in browser
  2. Create an app that renders this result to html, using a Python loop for the countdown:
    ready to takeoff
    10
    9
    8
    7
    6
    5
    4
    3
    2
    1
    blastoff
  3. create this pattern in html using Flask and a Python loop. Extension: make this scalable using a var in code:
    *
    * *
    * * *
    * * 
    *
  4. define a function processArray() that processes a list of 4 elements and writes them to html in reverse order:
    value: 7
    value: 3
    value: 3
    value: 1
  5. Solutions

    blastoff

    from flask import *
    app = Flask(__name__)
    
    @app.route("/")
    def go():
        markup = "ready to takeoff<br>"
        count = 10
        while (count >= 1):
            markup = markup + str(count) + "<br>"
            count = count - 1
        markup = markup + "blastoff"
        return markup
    
    app.run(debug=True)

    process array

    from flask import *
    app = Flask(__name__)
    
    myarray = [1,3,3,7]
    markup = ""
    
    @app.route("/")
    def go():
        processArray()
        return markup
    
    def processArray():
        global markup
        markup = ""
        for stuff in reversed(myarray):
            markup = markup + "value: " + str(stuff) + "<br>"
    
    app.run(debug=True)