Write a python program to create a sql table using python and accept 10 names and age .sort in descending order of age and display.

Priyalakshmi
2 min readJun 5, 2021

What we are going to do now?

In this program we are going to accept 10 names and age of the student using sql and going to display it in descending order based on their age.

What is sqlite3 in python?

SQLite3 is a very easy to use database engine. It is self-contained, serverless, zero-configuration and transactional. … The Python Standard Library includes a module called “sqlite3” intended for working with this database. This module is a SQL interface compliant with the DB-API 2.0 specification.

  1. We are importing sqlite3 and creating a database named as info.db and then creating a table named ad student in that we giving name and age of the student.

2.Creating a for loop to get a students name and their age .

for loop:

for loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there is no C style for loop, i.e., for (i=0; i<n; i++). There is “for in” loop which is similar to for each loop in other languages.

len()

Usually len() function is used to count the number of letters. But, in this program len() function is used to count the number f elements in the list.

3.Creating another for loop inside the for loop which is simply known as nested for loop to execute the name and age of the students. In this we used desc so it will display in descending order based on their age.

nested for loop:

A loop creating inside a loop is known as nested loop.

Output:

Here is the full code

To learn more about python sign in to Guvi

--

--