Bird
0
0

What will be the output of this Flask route code on a Raspberry Pi?

medium📝 Predict Output Q13 of 15
Raspberry Pi - Web Server and API
What will be the output of this Flask route code on a Raspberry Pi?
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/sensor')
def sensor():
    data = {'temperature': 22, 'humidity': 60}
    return jsonify(data)

# Assume app is running and /sensor is requested
A{"temperature": 22, "humidity": 60}
Btemperature=22, humidity=60
C<html><body>temperature: 22, humidity: 60</body></html>
DError: jsonify not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand jsonify function

    jsonify converts Python dict to JSON string with correct headers for API response.
  2. Step 2: Analyze route output

    The route returns JSON with keys 'temperature' and 'humidity' and their values.
  3. Final Answer:

    {"temperature": 22, "humidity": 60} -> Option A
  4. Quick Check:

    jsonify(dict) = JSON string [OK]
Quick Trick: jsonify returns JSON string from dict in Flask [OK]
Common Mistakes:
MISTAKES
  • Expecting plain text instead of JSON
  • Confusing jsonify with HTML output
  • Missing import of jsonify causing errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes