IP-GRADE-11 - Suggested Practical List Questions With Solutions
IP-GRADE-11 - Suggested Practical List Questions With Solutions
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.
5. Write a program to calculate the profit or loss for the given cost and selling price.
Ans.
6. Write a program to calculate the EMI for amount, period, and rate of interest.
Ans.
Ans.
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))
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)
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.
14. Write a program to print the number of occurrences of a given alphabet in each string.
Ans.
15. Write a program to create a dictionary to store names of states and their capitals.
Ans.
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.
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)
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)
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)
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)
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))
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.
42. Write a program to calculate the perimeter/circumference and area of shapes, such as triangle,
rectangle, square, and circle.
Ans.
44. Write a program to calculate profit/loss for the given cost and sell price.
Ans.
45. Write a program to calculate EMI for the given amount, time, and rate of interest.
Ans.
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.
50. Write a python program to check whether the number is positive or negative.
Ans.
else:
print("Negative number")
51. Write a program to read two numbers and prints their quotient and remainder.
Ans.
52. Write a Python program that create a list of names and update the list by adding a name to the
list.
Ans.
53. Consider the GARMENT database and answer the following SQL queries based on it:
e. To display codes and names of those garment that have their names starting with "Ladies".
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)
54. Consider the following table Faculty and write the queries based on it:
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.
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.
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.
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.