Hands On Practice
Hands On Practice
Hands on Practice
let min3 x y z :=
if x < y then
if x < z then
return (x)
else
return (z)
else
if y < z then
return (y)
else
return (z)
2. Write algorithmic recursive function definition to find the sum of n natural numbers
NO Hands on Practice
1. Observe the following diagram and Write the pseudo code for the following
1. sum()
2. num1 :=20
3. sum1()
4. num1:=num1 +10
5. sum2()
6. num1 := num1 + 10
7. sum2()
8. sum1()
9. num1 := 10
10. sum()
11. print num1
NO Hands on Practice
NO Hands on Practice
Enter a character :a
a is a vowel
Enter a character :x
x is not a vowel
Enter a number 1 :5
Enter a number 2 :3
Enter a number 3 :2
2 is smallest
Enter a number 1 :7
Enter a number 2 :9
Enter a number 3 :12
7 is smallest
Enter a number 0
0 is Zero
Enter a number -7
-7 is Negative
Enter N 10
Sum of numbers upto 10 is 55
for i in range(5,0,-1) :
for j in range(1,i+1):
print('*',end=' ')
print("\n")
*****
****
***
**
*
str=input("Enter a string")
length = len(str)
print ("Length of ",str," is ",length)
Enter a string You can not complete a sentence with because because because is a
conjunction
Enter a search string because
because is found 3 times in You can not complete a sentence with because because
because is a conjunction
5. Write a program to create a mirror of the given string. For example, “wel” = “lew“.
9. Write a program to replace a string with another string without using replace().
Number of lines = 3
Number of words = 29
Number of characters = 166
divBy3or6=[ ]
for i in range(1,51):
if i%3==0 or i%6 == 0:
divBy3or6.append(i)
print("List of elements from 1 to 51 divisible by 3 or 6")
print(divBy3or6)
8. Write a program to create a list of numbers in the range 1 to 20. Then delete all the
numbers from the list that are divisible by 3.
List Elements
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
List Elements After Removing numbers divisible by 3
[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20]
1. Write a program using class to store name and marks of students in list and print total
marks.
class Student:
__name=[]
__tamilmark=[]
__englishmark=[]
__mathsmark=[]
__totalmarks=[]
def getdata(self):
self.n = int(input("Enter number of students: "))
for x in range(self.n):
self.__name.append(input("Enter Student Name: "))
self.__tamilmark.append(int(input("Enter Tamil Mark: ")))
self.__englishmark.append(int(input("Enter English Mark: ")))
self.__mathsmark.append(int(input("Enter Maths Mark: ")))
def calculate_total(self):
for x in range(self.n):
self.__totalmarks.append(self.__tamilmark[x]+self.__englishmark[x]+
self.__mathsmark[x])
def display(self):
print("-------------------------------------------------")
print("Name\tTamil\tEnglish\tMaths\tTotal\t")
print("-------------------------------------------------")
for x in range(self.n):
print(self.__name[x], "\t", self.__tamilmark[x], "\t",self.__englishmark[x],
"\t",self.__mathsmark[x], "\t",self.__totalmarks[x])
print("-------------------------------------------------")
S = Student()
S.getdata()
S.calculate_total()
S.display()
import math
class Triangle:
def __init__(self,a,b,c):
self.__a=a
self.__b=b
self.__c=c
def area(self):
s = (self.__a+self.__b+self.__c)/2
tarea = math.sqrt(s*(s-self.__a)*(s-self.__b)*(s-self.__c))
return tarea
a=int(input("Enter length of triangle side 1: "))
b=int(input("Enter length of triangle side 2: "))
c=int(input("Enter length of triangle side 3: "))
T=Triangle(a,b,c)
print("The Area =",T.area())
class Distance:
def __init__(self):
self.__km = 0
self.__m = 0
def read(self):
self.__km = int(input("Enter Kilometer: "))
self.__m = int(input("Enter Meter: "))
def display(self):
print(self.__km,"Km",self.__m,"m")
def add(self,a,b):
totalmtr = a.__km * 1000 + a.__m + b.__km * 1000 + b.__m
self.__km = totalmtr // 1000
self.__m = totalmtr % 1000
def subtract(self,a,b):
totalmtr = (a.__km * 1000 + a.__m) – (b.__km * 1000 + b.__m)
self.__km = totalmtr // 1000
self.__m = totalmtr % 1000
choice = 1
while(choice!=5):
print("1. Read Two Distances\n2. Display Distances\n3. Add Two Distances\n4.
Subtract Two Distances\n5. Exit")
choice = int(input("Enter your choice : "))
if choice == 1:
print("Distance 1")
d1=Distance()
d1.read()
print("Distance 2")
d2=Distance()
d2.read()
elif choice == 2:
print("Distance 1")
d1.display()
NO Hands on Practice
1. Create a query of the student table in the following order of fields name, age, place
and admno.
+----------+------+-----------+-------+
| name | age | place | admno |
+----------+------+-----------+-------+
| Ashish | 17 | Chennai | 100 |
| Adarsh | 18 | Delhi | 101 |
| Akshith | 17 | Bangalore | 102 |
| Ayush | 21 | Delhi | 103 |
| Abinandh | 14 | Chennai | 104 |
+----------+------+-----------+-------+
2. Create a query to display the student table with students of age more than 18 with
unique city.
SELECT * from STUDENT where age > 18 and place IN (SELECT DISTINCT place
from STUDENT);
+-------+-------+--------+------+-------+
| Admno | Name | Gender | Age | Place |
+-------+-------+--------+------+-------+
| 103 | Ayush | M | 21 | Delhi |
+-------+-------+--------+------+-------+
4. In the above table set the employee number as primary key and check for NULL
values in any field.
1. Write a Python program to read the following Namelist.csv file and sort the data in
alphabetically order of names in a list and display the output
Name? Anu
Tamil Mark? 56
English Mark? 45
Maths Mark? 78
Science Mark? 56
Social Mark? 87
Name? Banu
Tamil Mark? 78
English Mark? 87
Maths Mark? 98
Science Mark? 91
Social Mark? 67
Name? Cheran
Tamil Mark? 89
1. Write a C++ program to create a class called Student with the following details
Protected member
Rno integer
Public members
void Readno(int); to accept roll number and assign to Rno
void Writeno(); To display Rno.
The class Test is derived Publically from the Student class contains the following details
Protected member
Mark1 float
Mark2 float
Public members
void Readmark(float, float); To accept mark1 and mark2
void Writemark(); To display the marks
Create a class called Sports with the following detail
Protected members
score integer
Public members
void Readscore(int); To accept the score
void Writescore(); To display the score
The class Result is derived Publically from Test and Sports class contains the following
details
Private member
Total float
Public member
void display() assign the sum of mark1, mark2, score in total. invokeWriteno(),
Writemark() and Writescore(). Display the total also.
Save the C++ program in a file called hybrid. Write a python program to execute the
hybrid.cpp
};
};
border.cpp
#include <iostream>
using namespace std;
int main()
{
int a[10][10], i, j,m,n;
cout<<"Number of Rows? ";
cin>>m;
cout<<"Number of Columns? ";
cin>>n;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
cout<<"enter the value for array["<<i+1<<"]"<<"["<<j+1<<"] :";
cin>>a[i][j];
}
}
cout<<"The Matrix\n";
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
cout<<a[i][j]<<' ';
cout<<endl;
}
Number of Rows? 5
Number of Columns? 5
enter the value for array[1][1] :1
enter the value for array[1][2] :5
enter the value for array[1][3] :8
enter the value for array[1][4] :6
enter the value for array[1][5] :2
enter the value for array[2][1] :9
enter the value for array[2][2] :0
enter the value for array[2][3] :6
enter the value for array[2][4] :4
enter the value for array[2][5] :2
enter the value for array[3][1] :1
enter the value for array[3][2] :4
enter the value for array[3][3] :8
enter the value for array[3][4] :6
enter the value for array[3][5] :9
enter the value for array[4][1] :2
enter the value for array[4][2] :1
enter the value for array[4][3] :4
enter the value for array[4][4] :3
enter the value for array[4][5] :9
enter the value for array[5][1] :5
enter the value for array[5][2] :2
enter the value for array[5][3] :0
enter the value for array[5][4] :1
enter the value for array[5][5] :6
1. Create an interactive program to accept the details from user and store it in a csv file
using Python for the following table.
Database name:- DB1
Table name : Customer
Cust_Id Cust_Name Address Phone_no City
C008 Sandeep 14/1 Pritam Pura 41206819 Delhi
C010 Anurag Basu 15A, Park Road 61281921 Kolkata
C012 Hrithik 7/2 Vasant Nagar 26121949 Delhi
(i) To display the name of all Games with their Gcodes in descending order of their
schedule date.
import sqlite3
connection = sqlite3.connect("DB2.db")
cursor = connection.cursor()
cursor.execute("SELECT Gcode, GameName FROM Games ORDER BY scheduleDate
DESC")
result = cursor.fetchall()
print(*result,sep="\n")
(ii) To display details of those games which are having Prize Money more than 7000.
import sqlite3
connection = sqlite3.connect("DB2.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Games WHERE PrizeMoney>7000")
result = cursor.fetchall()
print(*result,sep="\n")
import sqlite3
connection = sqlite3.connect("DB2.db")
cursor = connection.cursor()
cursor.execute("SELECT Name, GameName FROM Games ORDER BY GameName")
result = cursor.fetchall()
print(*result,sep="\n")
(iv) To display sum of PrizeMoney for each of the Number of participation groupings (as
shown in column Number 4)
import sqlite3
connection = sqlite3.connect("DB2.db")
cursor = connection.cursor()
cursor.execute("SELECT Number, sum(PrizeMoney) FROM Games GROUP BY
NUMBER")
result = cursor.fetchall()
print(*result,sep="\n")
1. Create a plot. Set the title, the x and y labels for both axes.