Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask module.
Raspberry Pi
from [1] import Flask
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Flask' instead of 'flask' as module name.
✗ Incorrect
The Flask module is imported using from flask import Flask.
2fill in blank
mediumComplete the code to create a Flask app instance.
Raspberry Pi
app = [1](__name__) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'flask' instead of 'Flask'.
✗ Incorrect
The Flask app instance is created by calling Flask(__name__).
3fill in blank
hardFix the error in the route decorator to serve sensor data at '/sensor'.
Raspberry Pi
@app.route('[1]') def sensor_data(): return {'temperature': 22.5, 'humidity': 60}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash.
Using uppercase letters in the path.
✗ Incorrect
The route must start with a slash and match the URL path exactly, so '/sensor' is correct.
4fill in blank
hardFill both blanks to return JSON response using Flask's jsonify function.
Raspberry Pi
from flask import Flask, [1] @app.route('/sensor') def sensor_data(): data = {'temperature': 22.5, 'humidity': 60} return [2](data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'json' instead of 'jsonify'.
Not importing jsonify.
✗ Incorrect
The jsonify function is imported and used to return JSON responses in Flask.
5fill in blank
hardFill all three blanks to run the Flask app on host '0.0.0.0' and port 5000.
Raspberry Pi
if __name__ == '__main__': app.run(host=[1], port=[2], debug=[3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '127.0.0.1' limits access to localhost only.
Setting debug to False during development.
✗ Incorrect
To make the Flask app accessible on the network, use host '0.0.0.0', port 5000, and enable debug mode with True.