🧮 5.
1 Programming in Python
---
Q1. To find average and grade for given marks.
marks = [85, 78, 92, 66, 74]
average = sum(marks) / len(marks)
if average >= 90:
grade = "A+"
elif average >= 80:
grade = "A"
elif average >= 70:
grade = "B"
elif average >= 60:
grade = "C"
else:
grade = "Fail"
print("Average Marks:", average)
print("Grade:", grade)
---
Q2. To find the sale price of an item with given cost and discount (%).
cost = float(input("Enter cost price: "))
discount = float(input("Enter discount percentage: "))
sale_price = cost - (cost * discount / 100)
print("Sale Price =", sale_price)
---
Q3. To calculate perimeter/circumference and area of shapes.
import math
# Example: Circle
r = float(input("Enter radius: "))
area = [Link] * r * r
circumference = 2 * [Link] * r
print("Area:", area)
print("Circumference:", circumference)
---
Q4. To calculate Simple and Compound Interest.
p = float(input("Enter principal: "))
r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))
si = (p * r * t) / 100
ci = p * (pow((1 + r / 100), t)) - p
print("Simple Interest =", si)
print("Compound Interest =", ci)
---
Q5. To calculate profit or loss.
cost = float(input("Enter Cost Price: "))
sell = float(input("Enter Selling Price: "))
if sell > cost:
print("Profit =", sell - cost)
elif cost > sell:
print("Loss =", cost - sell)
else:
print("No Profit No Loss")
---
Q6. To calculate EMI for amount, period, and interest.
p = float(input("Enter loan amount: "))
r = float(input("Enter annual interest rate: ")) / (12 * 100)
n = int(input("Enter number of months: "))
emi = (p * r * pow(1 + r, n)) / (pow(1 + r, n) - 1)
print("Monthly EMI =", round(emi, 2))
---
Q7. To calculate tax (GST / Income Tax).
amount = float(input("Enter amount: "))
gst_rate = float(input("Enter GST percentage: "))
gst = (amount * gst_rate) / 100
print("GST =", gst)
print("Total Amount =", amount + gst)
---
Q8. To find the largest and smallest numbers in a list.
numbers = [12, 45, 7, 89, 23]
print("Largest:", max(numbers))
print("Smallest:", min(numbers))
---
Q9. To find the third largest/smallest number in a list.
nums = [45, 22, 11, 89, 34, 67]
[Link]()
print("Third smallest:", nums[2])
print("Third largest:", nums[-3])
---
Q10. To find sum of squares of the first 100 natural numbers.
sum_sq = sum([i**2 for i in range(1, 101)])
print("Sum of squares of first 100 natural numbers:", sum_sq)
---
Q11. To print first ‘n’ multiples of a given number.
n = int(input("Enter number: "))
limit = int(input("Enter limit: "))
for i in range(1, limit + 1):
print(n * i)
---
Q12. To count the number of vowels in a string.
text = input("Enter a string: ")
count = 0
for ch in [Link]():
if ch in 'aeiou':
count += 1
print("Number of vowels:", count)
---
Q13. To print words starting with a given alphabet.
sentence = input("Enter a sentence: ")
char = input("Enter alphabet: ").lower()
words = [Link]()
for w in words:
if [Link]().startswith(char):
print(w)
---
Q14. To print number of occurrences of an alphabet.
string = input("Enter string: ")
ch = input("Enter alphabet: ").lower()
count = [Link]().count(ch)
print(f"'{ch}' occurs {count} times.")
---
Q15. Create a dictionary for states and capitals.
states = {"Bihar": "Patna", "UP": "Lucknow", "Rajasthan": "Jaipur",
"Maharashtra": "Mumbai"}
print(states)
---
Q16. Create dictionary of students with marks in 5 subjects.
students = {
"Ravi": [78, 82, 89, 74, 91],
"Anita": [67, 72, 88, 80, 79]
print(students)
---
Q17. To print highest and lowest values in dictionary.
marks = {"Ravi": 87, "Anita": 92, "Karan": 65, "Neha": 78}
print("Highest Marks:", max([Link]()))
print("Lowest Marks:", min([Link]()))
---
🗃 5.2 Data Management: SQL Commands
---
Q18. To create a database.
CREATE DATABASE School;
---
Q19. To create student table.
CREATE TABLE Student (
student_id INT PRIMARY KEY,
name VARCHAR(30),
class INT,
section CHAR(1),
gender CHAR(1),
dob DATE,
marks INT
);
---
Q20. To insert details of at least 10 students.
INSERT INTO Student VALUES
(1, 'Ravi', 12, 'A', 'M', '2006-03-12', 85),
(2, 'Anita', 12, 'B', 'F', '2006-07-22', 92),
(3, 'Rohit', 11, 'A', 'M', '2007-04-11', 70),
(4, 'Pooja', 12, 'A', 'F', '2006-09-10', 88),
(5, 'Arjun', 10, 'C', 'M', '2008-01-05', 56),
(6, 'Kiran', 12, 'A', 'F', '2006-05-14', 79),
(7, 'Mohan', 11, 'B', 'M', '2007-08-18', 60),
(8, 'Suman', 12, 'C', 'F', '2006-11-28', 91),
(9, 'Rakesh', 10, 'A', 'M', '2008-03-17', 49),
(10, 'Anand', 11, 'A', 'M', '2007-10-30', 75);
---
Q21. To display the entire content of table.
SELECT * FROM Student;
---
Q22. To display Rno, Name and Marks of students scoring more than 50.
SELECT student_id, name, marks FROM Student WHERE marks > 50;
---
Q23. To find average marks.
SELECT AVG(marks) AS Average_Marks FROM Student;
---
Q24. To find number of students from section ‘A’.
SELECT COUNT(*) FROM Student WHERE section = 'A';
---
Q25. To display students whose name starts with ‘AN’.
SELECT * FROM Student WHERE name LIKE 'AN%';
---
Q26. To display Rno, Name, DOB of students born between two dates.
SELECT student_id, name, dob
FROM Student
WHERE dob BETWEEN '2005-01-01' AND '2005-12-31';
---
Q27. To display male students in ascending order of names.
SELECT student_id, name, dob, marks
FROM Student
WHERE gender = 'M'
ORDER BY name ASC;
---
Q28. To display students in descending order of marks.
SELECT student_id, name, gender, dob, marks
FROM Student
ORDER BY marks DESC;
Q29. To display unique sections.
SELECT DISTINCT section FROM Student;