Bird
0
0

Identify the error in this Flask code snippet intended to run on Raspberry Pi:

medium📝 Debug Q14 of 15
Raspberry Pi - Web Server and API
Identify the error in this Flask code snippet intended to run on Raspberry Pi:
from flask import Flask
app = Flask(__name__)

@app.route('/status')
def status():
print('Server is running')

if __name__ == '__main__':
    app.run(host='0.0.0.0')
AIncorrect host value in app.run().
BMissing indentation for the print statement inside the function.
CMissing import statement for Flask.
DRoute decorator syntax is wrong.
Step-by-Step Solution
Solution:
  1. Step 1: Check function body indentation

    The print statement inside the function must be indented to be part of the function block.
  2. Step 2: Verify other parts

    Host value '0.0.0.0' is correct, Flask is imported, and route syntax is valid.
  3. Final Answer:

    Missing indentation for the print statement inside the function. -> Option B
  4. Quick Check:

    Python requires indentation inside functions [OK]
Quick Trick: Indent function code properly in Python [OK]
Common Mistakes:
MISTAKES
  • Ignoring indentation errors
  • Changing host unnecessarily
  • Misreading route decorator syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes