Bird
0
0

Given this Python code on Raspberry Pi:

medium📝 Predict Output Q4 of 15
Raspberry Pi - Data Logging and Databases
Given this Python code on Raspberry Pi:
import sqlite3
conn = sqlite3.connect('data.db')
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS readings (id INTEGER PRIMARY KEY, value REAL)')
cursor.execute('INSERT INTO readings (value) VALUES (23.5)')
conn.commit()
cursor.execute('SELECT value FROM readings WHERE id=1')
print(cursor.fetchone()[0])
conn.close()

What will be printed?
ANone
B23.5
C1
DError: no such table
Step-by-Step Solution
Solution:
  1. Step 1: Understand table creation and insertion

    The code creates a table 'readings' and inserts a value 23.5 with auto-increment id.
  2. Step 2: Query the value for id=1

    The first inserted row has id=1, so SELECT returns 23.5.
  3. Final Answer:

    23.5 -> Option B
  4. Quick Check:

    Inserted value fetched = 23.5 [OK]
Quick Trick: First inserted row gets id=1 by default [OK]
Common Mistakes:
MISTAKES
  • Expecting id instead of value
  • Assuming table does not exist
  • Forgetting to commit before select

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes