Information Practices (CBSE/NCERT)
SQL & Python Practice Set with Solutions
Part A: SQL Queries (with Solutions)
Q1. Create a table Student with fields RollNo, Name, Class, Marks, Grade.
CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(50),
Class VARCHAR(10),
Marks INT,
Grade CHAR(1)
);
Q2. Add a column DOB to the Student table.
ALTER TABLE Student ADD DOB DATE;
Q3. Modify column Marks to hold decimal values.
ALTER TABLE Student MODIFY Marks DECIMAL(5,2);
Q4. Drop column DOB from Student.
ALTER TABLE Student DROP COLUMN DOB;
Q5. Delete the Student table.
DROP TABLE Student;
Q6. Insert 5 records into Student.
INSERT INTO Student VALUES (101,'Amit','12A',85,'B');
INSERT INTO Student VALUES (102,'Riya','12B',92,'A');
INSERT INTO Student VALUES (103,'Neha','12A',76,'C');
INSERT INTO Student VALUES (104,'Rahul','12C',65,'D');
INSERT INTO Student VALUES (105,'Anita','12B',89,'B');
Q7. Display all records from Student.
SELECT * FROM Student;
Q8. Display RollNo and Name of students who scored more than 80.
SELECT RollNo, Name FROM Student WHERE Marks > 80;
Q9. Display names of students sorted by Marks in descending order.
SELECT Name, Marks FROM Student ORDER BY Marks DESC;
Q10. Count the number of students in Class 12A.
SELECT COUNT(*) FROM Student WHERE Class='12A';
Q11. Update Marks of a student with RollNo 101 to 95.
UPDATE Student SET Marks=95 WHERE RollNo=101;
Q12. Delete records of students having Grade 'D'.
DELETE FROM Student WHERE Grade='D';
Q13. Display maximum Marks scored.
SELECT MAX(Marks) FROM Student;
Q14. Display average Marks of all students.
SELECT AVG(Marks) FROM Student;
Q15. Display names of students whose name starts with 'A'.
SELECT Name FROM Student WHERE Name LIKE 'A%';
Q16. Display distinct classes from Student table.
SELECT DISTINCT Class FROM Student;
Q17. Display Name and Marks of top 3 students.
SELECT Name, Marks FROM Student ORDER BY Marks DESC LIMIT 3;
Q18. Display students with Marks between 60 and 80.
SELECT * FROM Student WHERE Marks BETWEEN 60 AND 80;
Q19. Display students with NULL Grade.
SELECT * FROM Student WHERE Grade IS NULL;
Q20. Display Grade-wise count of students.
SELECT Grade, COUNT(*) FROM Student GROUP BY Grade;
Part B: Python Programs (with Solutions)
Q1. Write a Python program to check whether a number is even or odd.
num = int(input('Enter a number: '))
if num % 2 == 0:
print('Even')
else:
print('Odd')
Q2. Program to find factorial of a number using loop.
num = int(input('Enter a number: '))
fact = 1
for i in range(1, num+1):
fact *= i
print('Factorial:', fact)
Q3. Program to generate Fibonacci series up to n.
n = int(input('Enter limit: '))
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a+b
Q4. Program to check if a string is palindrome.
s = input('Enter string: ')
if s == s[::-1]:
print('Palindrome')
else:
print('Not Palindrome')
Q5. Program to find largest of three numbers.
a, b, c = map(int, input('Enter three numbers: ').split())
print('Largest:', max(a, b, c))
Q6. Program to count vowels in a string.
s = input('Enter string: ')
vowels = 'aeiouAEIOU'
count = sum(1 for ch in s if ch in vowels)
print('Vowel count:', count)
Q7. Program to print multiplication table of a given number.
n = int(input('Enter number: '))
for i in range(1, 11):
print(n, 'x', i, '=', n*i)
Q8. Program to calculate sum of digits of a number.
n = int(input('Enter number: '))
sum_digits = sum(int(d) for d in str(n))
print('Sum of digits:', sum_digits)
Q9. Program to reverse a given list.
lst = [1,2,3,4,5]
print('Reversed list:', lst[::-1])
Q10. Program to find sum of elements of a list.
lst = [10,20,30]
print('Sum:', sum(lst))
Q11. Program to sort a list in ascending order.
lst = [5,2,9,1]
[Link]()
print('Sorted list:', lst)
Q12. Program to find common elements in two lists.
a = [1,2,3,4]
b = [3,4,5,6]
print('Common:', list(set(a) & set(b)))
Q13. Program to count frequency of words in a string using dictionary.
s = input('Enter text: ').split()
word_freq = {}
for w in s:
word_freq[w] = word_freq.get(w,0)+1
print(word_freq)
Q14. Program to demonstrate tuple packing and unpacking.
t = (1,2,3)
a,b,c = t
print(a,b,c)
Q15. Program to read a file and display its content.
f = open('[Link]','r')
print([Link]())
[Link]()
Q16. Program to count number of lines, words and characters in a file.
f = open('[Link]','r')
text = [Link]()
print('Lines:', [Link]('\n')+1)
print('Words:', len([Link]()))
print('Chars:', len(text))
[Link]()
Q17. Program to create a CSV file with student data.
import csv
f = open('[Link]','w',newline='')
writer = [Link](f)
[Link](['RollNo','Name','Marks'])
[Link]([101,'Amit',85])
[Link]([102,'Riya',92])
[Link]()
Q18. Program to read and display content of CSV file.
import csv
f = open('[Link]','r')
reader = [Link](f)
for row in reader:
print(row)
[Link]()
Q19. Program to create a pandas DataFrame from dictionary.
import pandas as pd
data = {'RollNo':[101,102],'Name':['Amit','Riya'],'Marks':[85,92]}
df = [Link](data)
print(df)
Q20. Program to display summary statistics of DataFrame.
import pandas as pd
data = {'RollNo':[101,102,103],'Marks':[85,92,76]}
df = [Link](data)
print([Link]())