0% found this document useful (0 votes)
25 views19 pages

IP-GRADE-11 - Suggested Practical List Questions With Solutions

The document provides a list of programming exercises with corresponding solutions in Python. It covers various topics including calculating averages, selling prices, areas of shapes, interest calculations, and working with lists and dictionaries. Each exercise includes a brief description and a complete code solution.

Uploaded by

examcellalwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
25 views19 pages

IP-GRADE-11 - Suggested Practical List Questions With Solutions

The document provides a list of programming exercises with corresponding solutions in Python. It covers various topics including calculating averages, selling prices, areas of shapes, interest calculations, and working with lists and dictionaries. Each exercise includes a brief description and a complete code solution.

Uploaded by

examcellalwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 19

IP Book 11

Suggested Practical List


1. Write a program to find the average of the given marks and assign the grades accordingly.
Ans.
print("Enter marks out of 100 in 5 subjects:")
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80 and avg<90):
print("Grade: B")
elif(avg>=70 and avg<80):
print("Grade: C")
elif(avg>=60 and avg<70):
print("Grade: D")
else:
print("Grade: F")

2. Write a program to find the sale price of an item with the given cost and discount percentage.
Ans.
price=float(input("Enter Price : "))
dp=float(input("Enter discount % : "))
discount=price*dp/100
sp=price-discount
print("Cost Price : ",price)
print("Discount: ",discount)
print("Selling Price : ",sp)

3. Write a program to calculate the perimeter/circumference and area of shapes, such as triangle,
rectangle, square, and circle.
Ans.
r=float(input("enter radius"))
s=float(input("enter side"))
l=float(input("enter length"))
b=float(input("enter breadth"))
area_cir = 3.14*r*r
area_sq = s*s
area_rec = l*b
print("area of circle: ", area_cir)
print("area of square: ", area_sq)
print("area of rectangle: ", area_rec)
4. Write a programming to calculate simple and compound interest.

Ans.

principal = float(input('Enter amount: '))


time = float(input('Enter time: '))
rate = float(input('Enter rate: '))
simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)
print("Simple interest is: ",simple_interest)
print("Compound interest is: ",compound_interest)

5. Write a program to calculate the profit or loss for the given cost and selling price.

Ans.

actual_cost = float(input(" Please Enter the Actual Product Price: "))


sale_amount = float(input(" Please Enter the Sales Amount: "))
if(actual_cost > sale_amount):
amount = actual_cost - sale_amount
print("Total Loss Amount = {0}".format(amount))
elif(sale_amount > actual_cost):
amount = sale_amount - actual_cost
print("Total Profit = {0}".format(amount))
else:
print("No Profit No Loss!!!")

6. Write a program to calculate the EMI for amount, period, and rate of interest.

Ans.

p = float(input("Enter principal amount: "))


R = float(input("Enter annual interest rate: "))
n = int(input("Enter number of months: " ))
# Calculating interest rate per month
r = R/(12*100)
# Calculating Equated Monthly Installment (EMI)
emi = p * r * ((1+r)**n)/((1+r)**n - 1)
print("Monthly EMI = ", emi)

7. Write a program to calculate the GST or the income tax.

Ans.

p = float(input("Enter Original amount: "))


np = float(input("Enter net price: "))
GST_amount = np - p
GST_percent = ((GST_amount * 100) / p)
print("GST = ", end='')
print(round(GST_percent), end='')
print("%")

8. Write a program to find the largest and smallest numbers in a list.

Ans.

lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :", min(lst))

9. Write a program to find the third largest/smallest number in a list.

Ans.

nlist = []
n = int(input("Enter the Total Number of List Elements: "))
for i in range(1, n + 1):
value = int(input("Enter the Value of %d Element : " %i))
nlist.append(value)
sorted_list = sorted(nlist)
print("Sorted elements in list : ",sorted_list)
print("The Third Smallest Element in this List is : ", sorted_list[2])
print("The Third Largest Element in this List is : ", sorted_list[-3])

10. Write a program to find the sum of squares of the first 100 natural numbers.

Ans.

n = 100
sum = 0
for s in range(1, n+1):
sum = sum + (s*s)
print("Sum of squares is : ", sum)

To print the first ‘n’ multiples of given number.


number = int(input("Enter number: "))

print("The multiples are: ")


for i in range(1,11):
print(number*i, end =" ")

11. Write a program to print the first ‘n’ multiples of a given number.

Ans.
12. Write a program to count the number of vowels in a user-entered string.

Ans.

string=input("Enter string:")
vowels=0
for i in string:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):
vowels=vowels+1
print("Number of vowels are:")
print(vowels)

13. Write a program to print the words starting with an alphabet in a user-entered string.

Ans.

s = input("Enter any sentences : ")


a = input("Enter any alphabet to find :")
found = False
words = s.split()
for word in words:
if word.startswith(a):
print(word)
found = True
if (found == False):
print("No word starting with user entered alphabet")

14. Write a program to print the number of occurrences of a given alphabet in each string.

Ans.

string = input("Please enter your own String : ")


char = input("Please enter your own Character : ")
count = 0
for i in range(len(string)):
if(string[i] == char):
count = count + 1
print("The total Number of Times ", char, " has Occurred = " , count)

15. Write a program to create a dictionary to store names of states and their capitals.

Ans.

capitals = {"Maharashtra" : "Mumbai",


"Delhi" : "New Delhi",
"Uttar pradesh":"Lucknow",
"Tamil Nadu ": " Chennai"}
print("Original Dictionary : ")
print(capitals)
capitals['Punjab'] = 'Chandigarh'
print()
print("After adding item in dictionary :")
print("Updated Dictionary:")
print(capitals)

16. Write a program to create a dictionary of students to store their names and marks obtained in
five subjects.

Ans.

students = dict()
n = int(input("Enter number of students :"))
for i in range(n):
sname = input("Enter names of student :")
marks= []
for j in range(5):
mark = float(input("Enter marks :"))
marks.append(mark)
students[sname] = marks
print("Dictionary of student created :")
print(students)

17. Write a program to print the highest and lowest values in a dictionary.

Ans.

dictionary = {"a": 5, "b": 2, "c": 8}


max_key = max(dictionary, key=dictionary.get)
print(max_key)
print(dictionary.get(max_key))
min_key = min(dictionary, key=dictionary.get)
print(min_key)
print(dictionary.get(min_key))

18. Write a program to display numbers from -10 to -1 using for loop.

Ans.

for i in range(-10,0):
print(i)
print the sum of the current number and the previous number.
n=int(input("enter any number"))
x=n-1
sum=n+x
print("sum of number and its prev number is : ", sum)
19. Write a program to print the sum of a number and its previous number.

Ans.
num = int(input("Enter a number: "))
sum = num + (num - 1)
print("The sum of the number and its previous number is:", sum)

20. Write a program to display the numbers divisible by 5 from a list.

Ans.

list1=[2,5,10,15,46,50]
for num in list1:
if num % 5 == 0:
print(num)
21. Write a program to check whether the entered number is a palindrome or not.

Ans.
num = 1221
temp = num
reverse = 0
while temp > 0:
remainder = temp % 10
reverse = (reverse * 10) + remainder
temp = temp // 10
if num == reverse:
print('Palindrome')
else:
print("Not Palindrome")

22. Write a Program to extract each digit from a number in the reverse order.
For example, if the given int is 7536, the output shall be "6 3 5 7" with a space separating the
digits. Use the else block to display the message, "Done", after successful execution of the for
loop.

Ans.

number = 7536
print("Given number", number)
while number > 0:
# get the last digit
digit = number % 10
# remove the last digit and repeat the loop
number = number // 10
print(digit, end=" ")
23. Write a program to display all the prime numbers within a given range.

Ans.
lower = 900
upper = 1000
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
24. Write a program to display the Fibonacci series up to 10 terms.

Ans.
# Program to display the Fibonacci sequence up to n-th term
nterms = int(input("How many terms? "))
# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
25. Write a program to find the factorial of a given number.

Ans.
# To take input from the user
num = int(input("Enter a number: "))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1, num + 1):
factorial = factorial*i
print("The factorial of", num, "is", factorial)
26. Write a program to display elements from a given list present at odd index positions.

Ans.
my_list = [31, 42, 13, 34, 85, 0, 99, 1, 3]
print("The list is :")
print(my_list)
print("The elements in odd positions are : ")
for i in range(1, len(my_list), 2):
print(my_list[i])
27. Write a program to calculate the cube of all the numbers from 1 to a given number.

Ans.
given_num = 5
for i in range(1, given_num):
x=i*i*i
print("cube of ",i,"is :",x)
28. Write a program to find the sum of the series up to n terms.

Ans.
n=5
x=0
for i in range(1,n+1):
x=i+x
print(x)

29. Print multiplication table of a number taken by user.

Ans.

number = int(input ("Enter the number of which the user wants to print the multiplication table: "))
print ("The Multiplication Table of: ", number)
for count in range(1, 11):
print (number, 'x', count, '=', number * count)

30. You are given with a list of integer elements. Make a new list which will store square of elements
of previous list.
Ans.
l1 = [1,2,3,4]
l2=[]
for i in l1:
l2.append(i**2)
print(l2)

31. Using the range (1, 101), create two lists: one containing all the even numbers and other
containing all the odd numbers.
Ans.
list1 = [11, 22, 33, 44, 55]
listOdd = []
listEven = []
for num in list1:
if num%2 == 0:
listEven.append(num)
else:
listOdd.append(num)
print("list1: ", list1 )
print("listEven: ", listEven)
print("listOdd: ", listOdd)

32. From the two lists obtained in the previous question, create new lists containing the numbers
that are divisible by 4, 6, 8, 10, 3, 5, 7 and 9 in separate lists..
Ans.
list1 = [11, 22, 33, 44, 55,49,63]
listdiv = []
listnotdiv = []
for num in list1:
if num%7 == 0:
listdiv.append(num)
else:
listnotdiv.append(num)
print("list1: ", list1 )
print("list divisible by 7: ", listdiv)
print("list not divisible by 7: ", listnotdiv)

33. Write a program to convert two lists into a dictionary.


Ans.
index = [1, 2, 3]
languages = ['python', 'c', 'c++']
dictionary = dict(zip(index, languages))
print(dictionary)

34. Write a program to merge two dictionaries into one dictionary.


Ans.
dict_1 = {1: 'a', 2: 'b'}
dict_2 = {2: 'c', 4: 'd'}
dict_3 = dict_2.copy()
dict_3.update(dict_1)
print(dict_3)

35. Write a program to initialise a dictionary with the default values.


Ans.
stu = ["Sita", "Syan", "Ram", "Pooja"]
defaults = {"role": "Student", "Department": "BCA"}
result = dict.fromkeys(stu, defaults)
print(result)

36. Write a program to create a dictionary by extracting the keys from a given dictionary.
Ans.
student = {"Name": "Tara", "RollNo":130046, "Mark": 458, "City": "Chennai"}
keys = ["Name", "RollNo", "Mark"]
n = {k: student[k] for k in keys}
print(n)

37. Write a program to delete a list of keys from a dictionary.


Ans.

test_dict = {'KIPS' : 1, 'is' : 2, 'best' : 3, 'for' : 4, 'CS' : 5}


rem_list = ['is', 'for', 'CS']
print("The original dictionary is : " + str(test_dict))
for key in rem_list:
del test_dict[key]
# printing result
print("Dictionary after removal of keys : " + str(test_dict))

38. Write a program to check if a value exists in a dictionary or not.


Ans.

myDict = {"name": "Python For Beginners", "book": "Comp Sc with Python KIPS", "acronym": "CS",
"type": "Reference"}
print("The dictionary is:")
print(myDict)
key = "name"
value = myDict[key]
print("The value associated with the key \"{}\" is \"{}\".".format(key, value))

39. Write a program to rename a key of a dictionary.


Ans.
# Define a dictionary
my_dict = {'old_key': 'value'}
# Define a function to rename a key
def rename_key(dictionary, old_key, new_key):
dictionary[new_key] = dictionary.pop(old_key)

# Call the function to rename the key


rename_key(my_dict, 'old_key', 'new_key')
# Print the updated dictionary
print(my_dict)

40. Write a program to find average and grade for given marks.
Ans.
student = {"name": "John", "age": 26, "address": "123 New York"}
student["NAME"]=student.pop("name")
print(student)
# find average and grade of given marks
print("Enter marks obtained in 5 subjects: ")
markOne = int(input())
markTwo = int(input())
markThree = int(input())
markFour = int(input())
markFive = int(input())
tot = markOne+markTwo+markThree+markFour+markFive
avg = tot/5
if avg>=91 and avg<=100:
print("Your Grade is A1")
elif avg>=81 and avg<91:
print("Your Grade is A2")
elif avg>=71 and avg<81:
print("Your Grade is B1")
elif avg>=61 and avg<71:
print("Your Grade is B2")
elif avg>=51 and avg<61:
print("Your Grade is C1")
elif avg>=41 and avg<51:
print("Your Grade is C2")
elif avg>=33 and avg<41:
print("Your Grade is D")
elif avg>=21 and avg<33:
print("Your Grade is E1")
elif avg>=0 and avg<21:
print("Your Grade is E2")
else:
print("Invalid Input!")

41. Write a program to find the sale price of an item with given cost and discount (%).
Ans.

price=float(input("Enter price : "))


dp=float(input("Enter discount % : "))
discount=price*dp/100
sp=price-discount
print("Cost Price : ", price)
print("Discount: ", discount)
print("Selling Price : ", sp)

42. Write a program to calculate the perimeter/circumference and area of shapes, such as triangle,
rectangle, square, and circle.

Ans.

len=int(input("Enter the length of rectangle:"))


bre=int(input("Enter the breadth of rectangle:"))
r=int(input("Enter the radius of circle:"))
area1=len*bre
perimeter=2*(len+bre)
area2=3.14*r*r
circum=2*3.14*r
print("Area of Rectangle =", area1)
print("Perimeter of Rectangle =", perimeter)
print("Area of Circle =", area2)
print("Circum of Circle =", circum)

43. Write a program to calculate the simple and compound interest.


Ans.

# Reading principal amount, rate and time


principal = float(input('Enter amount: '))
time = float(input('Enter time: '))
rate = float(input('Enter rate: '))
# Calcualtion
simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)
# Displaying result
print('Simple interest is: %f' % (simple_interest))
print('Compound interest is: %f' %(compound_interest))

44. Write a program to calculate profit/loss for the given cost and sell price.
Ans.

actual_cost = float(input(" Please Enter the Actual Product Price: "))


sale_amount = float(input(" Please Enter the Sales Amount: "))

if(actual_cost > sale_amount):


amount = actual_cost - sale_amount
print("Total Loss Amount = {0}".format(amount))
elif(sale_amount > actual_cost):
amount = sale_amount - actual_cost
print("Total Profit = {0}".format(amount))
else:
print("No Profit No Loss!!!")

45. Write a program to calculate EMI for the given amount, time, and rate of interest.
Ans.

principal = float(input('Enter amount: '))


time = float(input('Enter time: '))
rate = float(input('Enter rate: '))
simple_interest = (principal*time*rate)/100
print('Simple interest is: %f' % (simple_interest))
46. Write a program to count the number of vowels in the user-entered string.
Ans.

example = "Count number of vowels in a String in Python"


# initialising count variable
count = 0
# declaring a variable for index
i=0
for i in range(len(example)):
if (
(example[i] == "a")
or (example[i] == "e")
or (example[i] == "i")
or (example[i] == "o")
or (example[i] == "u")
):
count += 1
print("Number of vowels in the given string is: ", count)

47. Write a program for the two given integers x and n and compute x raise to the power n.
Ans.
x = int(input("Enter base number:"))
n = int(input("Enter exponent:"))
z = x**n
print(z)

48. Write a program to print first n natural numbers and their sum.
Ans.

n=int(input("Enter a number: "))


sum1 = 0
while(n > 0):
sum1=sum1+n
n=n-1
print("The sum of first n natural numbers is", sum1)

49. Write a program to find whether a given number is even or odd.


Ans.

num = int(input("Enter a number: "))


if (num % 2) == 0:
print("number is even")
else:
print("number is odd")

50. Write a python program to check whether the number is positive or negative.
Ans.

num = float(input("Enter a number: "))


if num > 0:
print("Positive number")

else:
print("Negative number")

51. Write a program to read two numbers and prints their quotient and remainder.
Ans.

a=int(input("Enter the first number: "))


b=int(input("Enter the second number: "))
quotient=a//b
remainder=a%b
print("Quotient is:", quotient)
print("Remainder is:", remainder)

52. Write a Python program that create a list of names and update the list by adding a name to the
list.
Ans.

names = ["Myra", "Parag", "Naina", "Katha"]


print('Current names List is:', names)
new_name = input("Please enter a name:\n")
names.append(new_name)
print('Updated name List is:', names)

Data Management – SQL Commands

53. Consider the GARMENT database and answer the following SQL queries based on it:

a. To create table garment using given data


mysql> CREATE TABLE GARMENT
-> (GCODE INT,
-> GNAME VARCHAR(30),
-> SIZE CHAR(3),
-> COLOUR CHAR(10),
-> PRICE DECIMAL(8,2));
Query OK, 0 rows affected (1.81 sec)

b. To insert rows into garment table

mysql> INSERT INTO GARMENT


-> (GCODE,GNAME,SIZE,COLOUR,PRICE)
-> VALUES
-> (111,"TSHIRT","XL","RED",1400.00),
-> (112,"JEANS","L","BLUE",1600.00),
-> (113,"SKIRT","M","BLACK",1100.00),
-> (114,"LADIES JACKET","XL","BLUE",4000.00),
-> (115,"TROUSERS","L","BROWN",1500.00),
-> (116,"LADIES TOP","L","PINK",1200.00)
-> ;
Query OK, 6 rows affected (0.33 sec)
Records: 6 Duplicates: 0 Warnings: 0

c. To display contents of garment table

mysql> SELECT * FROM GARMENT;


+-------+---------------+------+--------+---------+
| GCODE | GNAME | SIZE | COLOUR | PRICE |
+-------+---------------+------+--------+---------+
| 111 | TSHIRT | XL | RED | 1400.00 |
| 112 | JEANS | L | BLUE | 1600.00 |
| 113 | SKIRT | M | BLACK | 1100.00 |
| 114 | LADIES JACKET | XL | BLUE | 4000.00 |
| 115 | TROUSERS | L | BROWN | 1500.00 |
| 116 | LADIES TOP | L | PINK | 1200.00 |
+-------+---------------+------+--------+---------+
6 rows in set (0.01 sec)

d. To display names of those garments that are available in "L" Size.


mysql> SELECT GNAME
-> FROM GARMENT
-> WHERE SIZE = "L";
+------------+
| GNAME |
+------------+
| JEANS |
| TROUSERS |
| LADIES TOP |
+------------+
3 rows in set (0.61 sec)

e. To display codes and names of those garment that have their names starting with "Ladies".

mysql> SELECT GCODE,GNAME


-> FROM GARMENT
-> WHERE GNAME LIKE "LADIES%";
+--- ----+-------------
--+
| GCODE | GNAME
|
+--- ----+-------------
--+
| 114 | LADIES
JACKET |
| 116 | LADIES TOP
|
+--- ----+-------------
--+
2 rows in set (0.06
sec)

f. To display garment names, codes, and prices of the garments whose price is in range 1000.00
to 1500.00 (both 1000.00 and 1500.00 included)

mysql> SELECT GNAME, GCODE, PRICE


-> FROM GARMENT
-> WHERE PRICE BETWEEN 1000.00 AND 1500.00;
+------------+-------+---------+
| GNAME | GCODE | PRICE |
+------------+-------+---------+
| TSHIRT | 111 | 1400.00 |
| SKIRT | 113 | 1100.00 |
| TROUSERS | 115 | 1500.00 |
| LADIES TOP | 116 | 1200.00 |
+------------+-------+---------+
4 rows in set (0.11 sec)

54. Consider the following table Faculty and write the queries based on it:

a. Display the details of the faculties who joined after 1990.


SELECT *
FROM Faculty
WHERE doj<('1990-1-1');
b. Display details of the faculties whose salary is more than 20000.
SELECT *
FROM Faculty
WHERE fsal>20000;
c. Show the name of the faculties whose DOJ is 12-10-1980.
SELECT *
FROM Faculty
WHERE doj is ('1990-10-12');
d. Display "Annual Salary" of all the faculties (Given salary is monthly).
Select (fsal*12) as annual salary , fname
FROM Faculty
e. Display the record for Suman
SELECT *
FROM Faculty
WHERE fname='Suman';

55. Write an SQL query to create Student table with the student id, class, section, gender, name, dob,
and marks as attributes where the student id is the primary key.
Ans.
create table student (studentid int(4) primary key, class char(2), section
char(1), gender char(1), name varchar(20), dob date, marks decimal(5,2));

56. Write an SQL query to insert the details of at least 10 students in the above table.
Ans.
insert into student values (1101,'XI','A','M','Akash','2005/12/23',88.21),
(1102,'XI','B','F','Dev','2005/03/24',77.90),
(1103,'XI','A','F','Karan','2006/04/21',76.20),
(1104,'XI','B','M','Sharan','2005/09/15',68.23),
(1105,'XI','C','M','Megha','2005/08/23',66.33),
(1106,'XI','C','F','Pooja','2005/10/27',62.33),
(1107,'XI','D','M','Arjan','2005/01/23',84.33),
(1108,'XI','D','M','Amrita','2005/04/23',55.33),
(1109,'XI','C','F','Vishesh','2005/06/01',74.33),
(1110,'XI','D','F','Shruti','2005/10/19',72.30);

57. Write an SQL query to display the entire content of the Student table.
Ans. select * from student;

58. Write an SQL query to display Rno, Name, and Marks of those students who have scored more
than 50 marks.
Ans. select studentid, name, marks from student where marks>50;

59. Write an SQL query to find the average of marks from the Student table.
Ans.

mysql> select avg(marks) from student;


+------------+
| avg(marks) |
+------------+
| 72.549000 |
+------------+
1 row in set (0.48 sec)

60. Write an SQL query to find the number of students who are from section 'A'.
Ans.
mysql> select count(studentid) from student where section ='A';
+------------------+
| count(studentid) |
+------------------+
| 2|
+------------------+
1 row in set (0.11 sec)

61. Write an SQL query to display the information of all the students whose names start with 'AN'
(Examples: ANAND, ANGAD,..)
Ans.

mysql> select * from student where name like 'SH%';


+-----------+-------+---------+--------+--------+------------+-------+
| studentid | class | section | gender | name | dob | marks |
+-----------+-------+---------+--------+--------+------------+-------+
| 1104 | XI | B | M | Sharan | 2005-09-15 | 68.23 |
| 1110 | XI | D | F | Shruti | 2005-10-19 | 72.30 |
+-----------+-------+---------+--------+--------+------------+-------+
2 rows in set (0.00 sec)

62. Write an SQL query to display Rno, Name, and DOB of those students who are born between
'2005- 01-01' and '2005-12-31'.
Ans. Select studentid, Name, DOB from student where dob between 2005- 01-01 and
2005-12-31;

63. Write an SQL query to display Rno, Name, DOB, Marks, and Email of the male students in
ascending order of their names.
Ans.

mysql> select * from student order by name;


+-----------+-------+---------+--------+---------+------------+-------+
| studentid | class | section | gender | name | dob | marks |
+-----------+-------+---------+--------+---------+------------+-------+
| 1101 | XI | A | M | Akash | 2005-12-23 | 88.21 |
| 1108 | XI | D | M | Amrita | 2005-04-23 | 55.33 |
| 1107 | XI | D | M | Arjan | 2005-01-23 | 84.33 |
| 1102 | XI | B | F | Dev | 2005-03-24 | 77.90 |
| 1103 | XI | A | F | Karan | 2006-04-21 | 76.20 |
| 1105 | XI | C | M | Megha | 2005-08-23 | 66.33 |
| 1106 | XI | C | F | Pooja | 2005-10-27 | 62.33 |
| 1104 | XI | B | M | Sharan | 2005-09-15 | 68.23 |
| 1110 | XI | D | F | Shruti | 2005-10-19 | 72.30 |
| 1109 | XI | C | F | Vishesh | 2005-06-01 | 74.33 |
+-----------+-------+---------+--------+---------+------------+-------+
10 rows in set (0.05 sec)

64. Write an SQL query to display Rno, Gender, Name, DOB, Marks, and Email in descending order of
their marks.
Ans.
mysql> select * from student order by marks desc;
+-----------+-------+---------+--------+---------+------------+-------+
| studentid | class | section | gender | name | dob | marks |
+-----------+-------+---------+--------+---------+------------+-------+
| 1101 | XI | A | M | Akash | 2005-12-23 | 88.21 |
| 1107 | XI | D | M | Arjan | 2005-01-23 | 84.33 |
| 1102 | XI | B | F | Dev | 2005-03-24 | 77.90 |
| 1103 | XI | A | F | Karan | 2006-04-21 | 76.20 |
| 1109 | XI | C | F | Vishesh | 2005-06-01 | 74.33 |
| 1110 | XI | D | F | Shruti | 2005-10-19 | 72.30 |
| 1104 | XI | B | M | Sharan | 2005-09-15 | 68.23 |
| 1105 | XI | C | M | Megha | 2005-08-23 | 66.33 |
| 1106 | XI | C | F | Pooja | 2005-10-27 | 62.33 |
| 1108 | XI | D | M | Amrita | 2005-04-23 | 55.33 |
+-----------+-------+---------+--------+---------+------------+-------+
10 rows in set (0.00 sec)

65. Write an SQL query to display the details of the students whose names start with the letter "M".
Ans.

mysql> select distinct section from student;


+---------+
| section |
+---------+
|A |
|B |
|C |
|D |
+---------+
4 rows in set (0.04 sec)

You might also like