Challenge - 5 Problems
Request-Response Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Flask route return?
Consider this Flask route. What will the user see when they visit
/greet in their browser?Flask
from flask import Flask, request app = Flask(__name__) @app.route('/greet') def greet(): name = request.args.get('name', 'Guest') return f"Hello, {name}!"
Attempts:
2 left
💡 Hint
Look at how the code gets the 'name' from the URL query parameters and what default it uses.
✗ Incorrect
The route uses request.args.get('name', 'Guest') to get the 'name' parameter from the URL. If no name is provided, it defaults to 'Guest'. So visiting '/greet' without parameters returns 'Hello, Guest!'.
❓ state_output
intermediate2:00remaining
What is the response status code?
This Flask route returns a custom status code. What status code will the client receive?
Flask
from flask import Flask app = Flask(__name__) @app.route('/status') def status(): return 'All good', 202
Attempts:
2 left
💡 Hint
Look at the second value returned by the route function.
✗ Incorrect
The route returns a tuple with the response body and the status code 202. So the client receives HTTP status 202.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in Flask route?
Identify which Flask route code snippet will cause a syntax error when run.
Attempts:
2 left
💡 Hint
Check the function definition syntax carefully.
✗ Incorrect
Option A is missing a colon ':' after the function definition 'def bye()'. This causes a syntax error.
🔧 Debug
advanced2:00remaining
Why does this Flask route raise an error?
This Flask route raises an error when accessed. What is the cause?
Flask
from flask import Flask app = Flask(__name__) @app.route('/data') def data(): return json.dumps({'key': 'value'})
Attempts:
2 left
💡 Hint
Check if all used modules are imported.
✗ Incorrect
The code uses json.dumps but does not import the json module, causing a NameError.
🧠 Conceptual
expert3:00remaining
Why is understanding request-response cycle crucial in Flask?
Which statement best explains why understanding the request-response cycle is important when building Flask applications?
Attempts:
2 left
💡 Hint
Think about what happens when a user visits a Flask app URL.
✗ Incorrect
Understanding the request-response cycle helps developers control how data flows in and out of the app, which is essential for correct and secure behavior.