0
0
Raspberry Piprogramming~20 mins

Flask web server on Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask Master on Raspberry Pi
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Flask route response output
What is the output when you visit the root URL '/' of this Flask app running on Raspberry Pi?
Raspberry Pi
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello from Raspberry Pi!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
AHello World!
BHello from Raspberry Pi!
C500 Internal Server Error
D404 Not Found
Attempts:
2 left
💡 Hint
Look at the return value of the home() function.
🧠 Conceptual
intermediate
1:30remaining
Purpose of host='0.0.0.0' in Flask app
Why do we use host='0.0.0.0' when running a Flask app on Raspberry Pi?
ATo allow the Flask app to accept connections from any device on the network
BTo restrict the Flask app to only accept connections from localhost
CTo enable HTTPS encryption automatically
DTo run the Flask app on a random port
Attempts:
2 left
💡 Hint
Think about network accessibility from other devices.
🔧 Debug
advanced
2:30remaining
Identify the error in this Flask app code
What error will this Flask app code produce when run on Raspberry Pi?
Raspberry Pi
from flask import Flask
app = Flask(__name__)

@app.route('/hello')
def hello():
    return 'Hello!'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
AIndentationError: expected an indented block
BTypeError: app.route() missing required positional argument
CNameError: name 'app' is not defined
DNo error, runs fine
Attempts:
2 left
💡 Hint
Check the indentation of the function body.
Predict Output
advanced
2:00remaining
Flask app with dynamic URL parameter output
What is the output when visiting '/user/Alice' on this Flask app running on Raspberry Pi?
Raspberry Pi
from flask import Flask
app = Flask(__name__)

@app.route('/user/<name>')
def user(name):
    return f'User: {name}'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
A404 Not Found
BUser: <name>
CUser: Alice
DUser: user
Attempts:
2 left
💡 Hint
Look at how the URL parameter is used in the return string.
📝 Syntax
expert
3:00remaining
Identify the syntax error in this Flask app snippet
Which option correctly identifies the syntax error in this Flask app code snippet?
Raspberry Pi
from flask import Flask
app = Flask(__name__)

@app.route('/data')
def data():
    return {'value': 42}

if __name__ == '__main__':
    app.run(host='0.0.0.0')
AFlask app must import jsonify to return JSON data
BMissing colon after the function definition line
Capp.run() missing required port argument
DReturning a dictionary directly causes a TypeError because Flask expects a string or Response object
Attempts:
2 left
💡 Hint
Think about what Flask accepts as a return value from route functions.