12 Python + SQL
12 Python + SQL
3. What are operators in Python? Explain arithmetic, logical, and relational operators with
examples.
5. What are control flow statements? Explain if, elif, and else with examples.
10. What are variables in Python? How are they declared and assigned values?
13. Explain the difference between built-in functions and user-defined functions.
22. How do you handle exceptions in Python? Explain try, except, finally.
23. What are different types of exceptions in Python (e.g., TypeError, ValueError)?
25. Explain how to open, read, write, and close files in Python.
26. What are different file modes (e.g., 'r', 'w', 'a', 'x', 'b')?
32. Explain list indexing, slicing, and methods (e.g., append(), insert(), remove(), pop(), sort()).
33. What are tuples in Python? How are they different from lists?
64. Explain different types of trees (binary tree, binary search tree).
IV. Databases
69. What are different types of database models (relational, hierarchical, network)?
79. Write SQL queries for selecting data with different conditions (WHERE clause).
82. Write SQL queries for joining tables (INNER JOIN, LEFT JOIN, RIGHT JOIN).
83. What are aggregate functions (COUNT, SUM, AVG, MAX, MIN)?
V. Boolean Algebra
89. Simplify Boolean expressions using Boolean laws (e.g., De Morgan's laws, distributive law).
90. What are logic gates (AND, OR, NOT, XOR, NAND, NOR)?
VI. Networking
111. What are different types of cloud services (IaaS, PaaS, SaaS)?
125. Write a Python program to read data from a file and count the number of words.
130. Write SQL queries to create tables, insert data, and retrieve data based on various
conditions.
1. Write a program to input two numbers and print their sum, difference, product, and
quotient.
4. Write a program to calculate the area of a triangle given its base and height.
25. Write a program to print all prime numbers within a given range.
29. Write a program to print patterns using nested loops (e.g., triangle, pyramid, square).
30. Write a program to find the greatest common divisor (GCD) of two numbers.
31. Write a program to find the least common multiple (LCM) of two numbers.
33. Write a program to validate user input (e.g., check if input is a number).
38. Write a program to find the sum of even numbers in a given range.
39. Write a program to find the sum of odd numbers in a given range.
42. Write a program to find the perfect numbers within a given range.
58. Write a function that takes a list as input and returns the sum of its elements.
59. Write a function that takes a string as input and returns the number of words.
60. Write a function that takes a list as input and returns a new list with unique elements.
67. Write a function to find the largest and smallest number in a list.
81. Write a program to create a list of even numbers from a given list.
82. Write a program to create a list of odd numbers from a given list.
86. Write a program to find the largest and smallest element in a list.
96. Write a program to read data from a text file and print it.
106. Write a program to read data from a file and store it in a list.
114. Write a program to read data from a file and calculate the sum of numbers.
115. Write a program to read data from a file and find the average of numbers.
116. Write a program to read data from a file and find the largest and smallest number.
1. Write an SQL statement to create a table named "Students" with columns: StudentID (INT,
Primary Key), Name (VARCHAR(50)), Age (INT), and Marks (DECIMAL(5,2)).
2. Write an SQL statement to insert a new student record into the "Students" table with values:
StudentID=1, Name='John Doe', Age=17, and Marks=95.50.
3. Write an SQL statement to select all columns and rows from the "Students" table.
4. Write an SQL statement to select only the Name and Marks columns from the "Students"
table.
5. Write an SQL statement to select all students whose Age is greater than 16.
6. Write an SQL statement to select all students whose Marks are between 80 and 90
(inclusive).
7. Write an SQL statement to update the Marks of the student with StudentID=1 to 98.00.
10. Write an SQL statement to add a new column named "City" (VARCHAR(50)) to the "Students"
table.
11. Write an SQL statement to select all students whose Name starts with the letter 'A'.
12. Write an SQL statement to select all students whose Name contains the word 'Doe'.
13. Write an SQL statement to select all students whose Age is NOT equal to 18.
14. Write an SQL statement to select all students whose Marks are greater than 75 AND Age is
less than 18.
15. Write an SQL statement to select all students whose City is 'New York' OR 'London'.
16. Write an SQL statement to find the average Marks of all students.
17. Write an SQL statement to find the highest and lowest Marks in the "Students" table.
18. Write an SQL statement to count the total number of students in the table.
19. Write an SQL statement to find the sum of all Marks in the "Students" table.
20. Write an SQL statement to find the average Marks of students grouped by their City. (Assume
"City" column exists).
21. Write an SQL statement to select all students and order the results by Name in ascending
order.
22. Write an SQL statement to select all students and order the results by Marks in descending
order.
23. Write an SQL statement to select all distinct City values from the "Students" table.
V. Joins (3)
Assume you have another table named "Courses" with columns: CourseID (INT, Primary Key),
CourseName (VARCHAR(50)). And a table "StudentCourses" with columns: StudentID (INT,
Foreign Key referencing Students), CourseID (INT, Foreign Key referencing Courses).
24. Write an SQL statement to select the Name of students and the CourseName they are
enrolled in using an INNER JOIN.
25. Write an SQL statement to select all students and the courses they are enrolled in, even if
they are not enrolled in any course (LEFT JOIN).
26. Write an SQL statement to retrieve all courses and the students enrolled, even if no students
are enrolled in a course (RIGHT JOIN).
27. Write an SQL statement to add a CHECK constraint to the "Students" table to ensure that Age
is always greater than 0.
28. Write an SQL statement to add a UNIQUE constraint to the Name column of the "Students"
table (assuming it doesn't have one already).
29. Explain the difference between PRIMARY KEY and FOREIGN KEY.