Bird
0
0

You wrote this Flask app on Raspberry Pi but get an error when running it:

medium📝 Debug Q6 of 15
Raspberry Pi - Web Server and API
You wrote this Flask app on Raspberry Pi but get an error when running it:
from flask import Flask
app = Flask(__name__)

@app.route('/hello')
def hello():
print('Hello from Raspberry Pi')

if __name__ == '__main__':
    app.run()

What is the main problem?
AMissing return statement in the function
BThe print statement is not indented inside the function
CIncorrect route decorator syntax
DFlask app is not created properly
Step-by-Step Solution
Solution:
  1. Step 1: Check function indentation

    Python requires code inside functions to be indented. The print statement is not indented, causing a syntax error.
  2. Step 2: Confirm other parts are correct

    The route decorator and app creation are correct; missing return is not an error but affects response.
  3. Final Answer:

    The print statement is not indented inside the function -> Option B
  4. Quick Check:

    Indentation error = print not indented [OK]
Quick Trick: Indent all code inside functions in Python [OK]
Common Mistakes:
MISTAKES
  • Ignoring indentation errors
  • Assuming missing return causes syntax error
  • Thinking route decorator syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes