In this example we are going to accept data using Python input() command during runtime and then going to write in the Table called “Person”
Example
# code for executing query using input data
import sqlite3
#creates a database in RAM
con =sqlite3.connect(“Academy,db”)
cur =con.cursor( )
cur.execute(“DROP Table person”)
cur.execute(“create table person (name, age, id)”)
print(“Enter 5 students names:”)
who =[input( ) for i in range(5)]
print(“Enter their ages respectively:”)
age =[int(input()) for i in range(5)]
print(“Enter their ids respectively:”)
p_d =[int(input( ))for i in range(5)]
n =len(who)
for i in range(n):
#This is the q-mark style:
cur.execute(“insert into person values(?,?,?)” , (who[i], age[i], p_id[i]))
#And this is the named style:
cur.execute(“select *from person”)
#Fetches all entries from table
print(“Displaying All the Records From Person Table”)
print (*cur.fetchall(), sep= ’\n’)
OUTPUT
Enter 5 students names:
RAM
KEERTHANA
KRISHNA
HARISH
GIRISH
Enter their ages respectively:
28
12
21
18
16
Enter their ids respectively:
1
2
3
4
5
Displaying All the Records From Person Table
(‘RAM’ , 28, 1)
(‘KEERTHANA’ , 12, 2)
(‘KRISHNA’ , 21, 3)
(‘HARISH’ , 18,4)
(‘GIRISH’ , 16, 5)