Bird
0
0

Which of the following is the correct way to start a simple web server on a Raspberry Pi using Python?

easy📝 Syntax Q12 of 15
Raspberry Pi - Web Server and API
Which of the following is the correct way to start a simple web server on a Raspberry Pi using Python?
import http.server
import socketserver

PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    httpd._____()
Aserve_forever
Blisten
Cstart_server
Drun
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method to keep the server running

    The method serve_forever() keeps the server active and listening for requests.
  2. Step 2: Match the method name in the code

    The code uses httpd._____(), so the correct method to fill is serve_forever.
  3. Final Answer:

    serve_forever -> Option A
  4. Quick Check:

    Keep server running = serve_forever() [OK]
Quick Trick: Remember Python server uses serve_forever() to run [OK]
Common Mistakes:
MISTAKES
  • Using run() which does not exist
  • Using start_server() which is not a method
  • Using listen() which is for sockets, not HTTPServer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes