0% found this document useful (0 votes)
2 views

Lab Report Fininshng Textmaker

The document contains a series of programming exercises aimed at demonstrating various programming concepts in Python and SQL. Each experiment includes an objective, code implementation, and a result indicating successful execution. Topics covered include Floyd's triangle, palindrome checking, arithmetic calculations, database operations, and file handling.

Uploaded by

aimenbusiness8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab Report Fininshng Textmaker

The document contains a series of programming exercises aimed at demonstrating various programming concepts in Python and SQL. Each experiment includes an objective, code implementation, and a result indicating successful execution. Topics covered include Floyd's triangle, palindrome checking, arithmetic calculations, database operations, and file handling.

Uploaded by

aimenbusiness8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

OUTPUT:-

FLOYD TRIANGLE
EXP NO:01

DATE:14/10/24

AIM:-
Program to print floyd triangle upto a limit.

PROGRAM:-
def floyd_triangle(n):
k=0
for i in range(1,n+1):
for i in range(1,i+1):
k=k+1
print(k,end="")
print()

floyd_triangle(5)

RESULT:-
The above program is succesfully executed and veriefied.
OUTPUT:-
PALINDROME
EXP NO:02

DATE:14/10/24

AIM:-
Program to check whether a string is palimdrom or not.

PROGRAM:-
def is_palindrome(s):
return s==s[::-1]

#test the function


print(is_palindrome('racecar'))#true
print(is_palindrome('hello'))#false

RESULT:-
The above program is succesfully executed and verified.
OUTPUT:-
ODD OR EVEN
EXP NO:03

DATE:14/10/24

AIM:-
Write a program using functions to check whether a number is even or odd.

PROGRAM:-
def oddeven(a):
if(a%2==0):
return 1
else:
return 0
num=int(input("enter a number:"))
if(oddeven(num)==1):
print("The given number is even")
elif(oddeven(num)==0):
print("The given number is Odd")

oddeven(17)

RESULT:-
The program is succesfully executed and verified.

OUTPUT:-
ARITHMETIC CALCULATOR
EXP
NO:04

DATE :14/10/24

AIM:-
Program to create a basic calculator.

PROGRAM:-
result = 0
val1 = float(input("Enter the first value :"))
val2 = float(input("Enter the second value :"))
op = input("Enter any one of the operator (+,-,,///,%)")
if op == "+":
result = val1 + val2
elif op == "-":
result = val1 - val2
elif op == "*":
result = val1 * val2
elif op == "/":
if val2 == 0:
print("Please enter a value other than 0")
else:
result = val1/val2
elif op == "//":
result = val1 // val2
else:
result = val1 % val2
print("The result is :",result)

RESULT:-
The above program is successfully executed and verified.
OUTPUT:-
PERFECT SQUARE
EXP
NO:05

DATE:14/10/24

AIM:-
Program to find wether a program is perfect square or not.

PROGRAM:-
import math
def perfectsquare(n):
root=math.sqrt(n)
return root.is_integer()

print(perfectsquare(16))
print(perfectsquare(15))

RESULT:-
The above program is succesfullly executed and verified.
OUTPUT:-
FACTORIAL NUMBER
EXP
NO:06

DATE:14/10/24

AIM:-
Program to find factorial of a number.

PROGRAM:-
def factorial(n):
result=1
for i in range(2,n+1):
result*=i
return result
print(factorial(4))
print(factorial(5))

RESULT:-
The above program is succesfully executed and verifed.
OUTPUT:-
ARMSTRONG NUMBER
EXP
NO:07

DATE:14/10/24

AIM:-
Program to find whether the number is Armstrong or not.

PROGRAM:-
def is_armstrong(n):
num_digits = len(str(n))
sum = 0
for digit in str(n):
sum += int(digit)**num_digits
return sum== n

print(is_armstrong(153))
print(is_armstrong(371))

RESULT:-
The above program is succesfully executed and verified.
OUTPUT:-
FIBONACCI SERIES
EXP
NO:08

DATE:14/10/24

AIM:-
Program to print Fibonacci series upto a limit.

PROGRAM:-
def fibonacci(n):
sequence=[0,1]
for i in range(2,n):
sequence.append(sequence[i-1]+sequence[i-2])
return sequence

print(fibonacci(int(input("enter any number:"))))

RESULT:-
The above program is succesfully executed and verified succesfully.
OUTPUT:-
IMPLEMENTATION OF LIST AS STACK
EXP
NO:09

DATE:14/10/24
AIM:-
To write a python program to implement all basic operations of a stack, such as
adding element (PUSH operation), removing element (POP operation) and
displayingthe stack elements (Traversal operation) using lists.

PROGRAM:-
stack=[ ]
choice='y'
while choice=='y':
print("1.PUSH")
print("2.POP")
print("3.Display")
c=int(input("Enter your choice:"))
if c==1:
a=input("enter any number:")
stack.append(a)
elif c==2:
if stack==[ ]:
print("Stack empty")
else:
print("Deleted element is:",stack.pop())
elif c==3:
for i in range(len(stack)-1,-1,-1):
print(stack[i])
else:
print("Wrong input")
choice=input("Do you want to continue or not?")
if choice=='Nn':
Break

RESULT:
The above program is successfully executed and verified.

OUTPUT:-
DISPLAYING UNIQUE VOWELS
EXP
NO:10

DATE:14/10/24

AIM:-
Write a program to display unique vowels present in the given word using stack.

PROGRAM:-
vowels=['a','e','i', 'o', 'u']
word=input("Enter the word to search for vowels:")
Stack=[]
for letter in word:
if letter in vowels:
if letter not in Stack:
Stack.append(letter)
print(Stack)
print("The number of different vowels present in",word,"is",len(Stack))

RESULT:-
The above program is successfully executed and verified.

OUTPUT:-

File:-
APPENDING INTO A TEXT FILE
EXP NO:11

DATE:14/10/24

AIM:-
Program to write data to a text file in append mode.

PROGRAM:-
af=open("travis.txt","a")
line_of_text=("one line of txt here","and anoter line here","and so on and so
forth")
af.writelines('\n'.join(line_of_text))
af.close()
RESULT:-
The above program is succesfully executed and verified.

OUTPUT:-

File:-
WORD REPEATITION IN A STRING
EXP
NO:12

DATE:14/10/24

AIM:-
Write a program to read data from data file and count the particular word
occurences in a given string.

PROGRAM:-
f=open('school.txt','r')
read=f.readlines()
f.close()
times2=0
times=0
chk=input("enter string to search:")
count=0
for sentence in read:
line=sentence.split()
times+=1
for each in line:
line2=each
times2+=1
if chk==line2:
count+=1
print("the searched string",chk, "is present:",count,"times")
print("number of lines present:",times,"times")
print("number of words present:",times2,"times")

RESULT:-
The above program is succesfully executed and verified.

OUTPUT:-
READING AND APPENDING DATA
EXP NO:13

DATE:14/10/24

AIM:-
Write a program to read data from data file in read mode and print the words
starting with letter 'T 'in python.

PROGRAM:-
f=open("TEXTS.txt","r")
read=f.readlines()
f.close()
id=[]
for In in read:
if In.startswith("T"):
id.append(In)
print(id)

RESULT:-
The above program is succesfully executed and verified.
OUTPUT:-
READNG AND WRITING IN A BINARY FILE
EXP
NO:14

DATE:14/10/24

AIM:-
Program to write and read in a binary file.

PROGRAM:-
import pickle
def write():
f=open("binary.txt","wb")
data=[]
while True:
eno=int(input("enter employee number"))
ename=input("enter employee name")
salary=int(input("enter salary"))
rec=[eno,ename,salary]
data.append(rec)
ch=input("do you want to add more data Y/N")
if ch in "Nn":
break
pickle.dump(data,f)
f.close()

def read():
f=open("binary.txt","rb")
data=pickle.load(f)
print(data)
f.close()

write()
read()
RESULT:-
The above program is succesfully executed and verified.

OUTPUT:-
READING AND WRITING IN A CSV FILE
EXP NO:15

DATE:14/10/24

AIM:-
Program to read and write in a csv file.

PROGRAM:-
import csv
def write():
f=open("school.csv","w")
wo=csv.writer(f)
wo.writerow(["rno","name","marks"])
while True:
r=int (input("enter roll no:"))
n=input("enter name")
m=int(input("enter marks"))
rec=[r,n,m]
wo.writerow(rec)
ch=input("do you want to add more data Y/N")
if ch in "Nn":
break
f.close()

def read():
f=open("school.csv","r")
ro=csv.reader(f)
for i in ro:
print(i)
f.close()

write()
read()

RESULT:-
The above program is succesfully executed and verified.

OUTPUT:-
TABLE CREATION
EXP NO:16

DATE:15/10/24

AIM:-
To write database connectivity program for creating table with name,emp,salary.

PROGRAM:-
import mysql.connector as s
db=s.connect(host='localhost',user='root',password='123456',database='school')
cursor=db.cursor()
sql="CREATE TABLE employeee(empno int primary key,ename varchar(25)not
null,salary float);"
cursor.execute(sql)
db.close()
RESULT:-
The above program is succesfully executed and veriified.

OUTPUT:-
INSERTING VALUES
EXP
NO:17

DATE:15/10/24

AIM:-
Write a python program to iinsert the following record in a table emp.

PROGRAM:-
import mysql.connector as s
db=s.connect(host='localhost',user='root',password='123456',database='school')
cursor=db.cursor()
sql='INSERT INTO employeee VALUES(1,"ANILKUMAR",86000);'
try:
cursor.execute(sql)
except:
pass
db.commit()

RESULT:-
The above program is succesfully executed and verified.
OUTPUT:-
FETCHING ALL THE RECORDS
EXP NO:18

DATE:14/10/24

AIM:-
Write a database connectivity program to fetching all the records from EMP table
having salary more than 70000.

PROGRAM:-
import mysql.connector as d
db=d.connect(host='localhost',user='root',password='123456',database="school
")
cursor=db.cursor()
sql=’select * from emp where salary>70000;'
try:
cursor.execute(sql)
resultset=cursor.fetchall()
for row in resultset:
print(row)
except:
print("error unable to fetch data")
db.close()

RESULT:-
The above program is successfully executed and verified.
OUTPUT:-
UPDATING RECORDS OF A TABLE
EXP
NO:19

DATE:14/10/24

AIM:-
Write a database connectivity program to update records of a table.

PROGRAM:-
import mysql.connector as s
db=s.connect(host='localhost',user='root',password='123456',database="school"
)
cursor=db.cursor()
sql=’update emp set salary=salary+1000 where salary<80000;'
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
finally:
cursor.close()
db.close()
RESULT:-
The above program is succesfully executed and verified.

OUTPUT:-
CREATING SQL PROGRAM 1
EXP NO:20

DATE:14/10/24
AIM:-

Consider the table exam given below. Write commands in SQL form.

SL_NO NAME STIPEND SUBJECT AVERAGE DIVISION


1 Khan 400 English 68 1
2 Aman 680 Maths 72 1
3 Javad 500 Accountancy 76 1
4 Vyshak 200 Informatics 55 2
5 Sughanda 400 History 35 3
6 Subarna 550 Geography 45 3

1. List the name of persons who have obtained division 1 in ascending order.

2. Display name, subject, stipend from exam.

3. Find the number of students who have either accountancy or


informatics as subject.
4. To insert a new row in the table exam
(6,'mohan',500,'english',72,2).

5. Select avg(STIPEND) from exam where DIVISION=3.

6. Select distinct(SUBJECT) from exam.

7. Select min(AVERAGE) from exam where


SUBJECT='English'.

8. Select max(AVERAGE) from exam where SUBJECT='English'.


QUERY:-
QUERY 1:-
SELECT NAME FROM exam WHERE DIVISION=1 ORDER BY NAME ASC;

QUERY 2:-
SELECT NAME, STIPEND, SUBJECT FROM exam;

QUERY 3:-
SELECT SUBJECT, COUNT(*) FROM exam GROUP BY SUBJECT HAVING
SUBJECT='Accountancy' OR SUBJECT='Informatics';

QUERY 4:-
INSERT INTO exam VALUES(11, 'Mohan', 500, 'English',72,2);

QUERY 5:-
SELECT AVG (STIPEND) FROM exam WHERE DIVISION=3;

QUERY 6:-
SELECT DISTINCT SUBJECT FROM exam;

QUERY 7:-
SELECT MIN(AVERAGE) FROM exam WHERE SUBJECT='English';

QUERY 8:-
SELECT MAX(AVERAGE) FROM exam WHERE SUBJECT='English';

\
OUTPUT:-
CREATING SQL PROGRAM 2

EXP NO:21

DATE:14/10/24

AIM:-
Consider the table employees. Write command in SQL form.

P_ID SUR_NAME FIRST_NAM GENDER CITY PINCODE SALARY


E
1 Shahama Mohd F Manjeri 123456 50000
2 Singh Surendra M Calicut 846256 75000
3 Jacob Thomas M Kappad 785694 45000
4 Allen Peter M Palakkad 159357 80000
5 Mohan Aneesh M Ernad 459986 33000
6 Sha Azim M Kolapad 159874 40000
7 Abdullah Raniya F Patambi 456574 4000

1. Display the SUR NAME, FIRST NAME, CITY of employees residing in Manjeri.

2. Display P_ID, CITY, PINCODE of employees in descending order of pincode.

3. Display FIRST_NAME, SALARY of all employees where SALARY is less than


42000.

4. Display FIRST_NAME, CITY of all getting salary above 42000.

5. To display total SALARY of females


.
6. To count the number of employees, they are getting SALARY less than 35000.
QUERY:-

QUERY 1:-
SELECT SUR_NAME, FIRST_NAME, CITY FROM employees WHERE CITY='Manjeri';

QUERY 2:-
SELECT P_ID, CITY, PINCODE FROM employees ORDER BY PINCODE DESC;

QUERY 3:-
SELECT FIRST_NAME, SALARY FROM employees WHERE SALARY<42000;

QUERY 4:-
SELECT FIRST_NAME, SALARY FROM employees WHERE SALARY>42000;

QUERY 5:-
SELECT SUM(SALARY) FROM employees WHERE GENDER='F';

QUERY 6:-
SELECT COUNT(*) FROM employees WHERE SALARY<45000;
OUTPUT:-
CREATING SQL PROGRAM 3
EXP
NO:22

DATE:15/10/24

AIM:-
Consider the table shop given below. Write the commands in SQL form.
SCODE PNAME SUPNAME QTY CITY PRICE
102 Biscuit Hide&seek 100 Delhi 10
103 Jam Kissan 110 Kolkatta 25
101 Coffee Nestle 200 Kolkata 55
106 Noodles Maggie 56 Mumbai 55
107 Cake Britania 72 Delhi 10
104 Tea Nestle 156 Mumbai 10
105 Chocolate Kitkat 120 Delhi 25
1. Display the P_NAME of the product in ascending order of the price
.
2. Display CODE, P_NAME and CITY of the product whose QTY is less than 100.

3. To count Distinct SUP_NAME in the table.

4. To insert a new row in the table shown (110,'pizza',


'papajohns',120,'calicut',50.00).

5. To display the P_NAME and SUP_NAME, those are serving their product in
Mumbai or kolkatta.

6. To display the highest value of QTY that serves in Mumbai.


QUERIES:-
QUERY 1:-
select PNAME from product order by PRICE asc;

QUERY2:-
select SCODE, PNAME, CITY FROM product where QTY>100;

QUERY 3:-
select count(DISTINCT SUPNAME) FROM PRODUCT;
QUERY 4:-
select PNAME, SUPNAME from product where CITY='Mumbai' or CITY='Kolkata';

QUERY 5:-
INSERT into product values(110, 'Pizza', 'Papa johns',120, 'Calicut',50);

QUERY 6:-
select MAX(QTY) FROM product where CITY='Mumbai';

OUTPUT:-
CREATING MYSQL PROGRAM 4
EXP
NO:23

DATE:15/10/24
AIM:-
Consider the table teachers given below. Write commands in SQL form.
id name department hiredate category gender salary
1 thomas Social science 17-02-2021 trt M 25000
2 sangeeth art 12-02-2020 trt M 30000
3 rajeev english 16-05-1998 pgt M 50000
4 yamin english 16-10-1986 tgt M 15000
5 Raniya faumi maths 17-11-1980 tgt M 60000
6 elizabeth science 21-01-2021 tgt F 70000
7 malik maths 28-02-2020 prt M 85000
8 victoria hindi 31-10-1990 prt F 95000

1. Display all the details of teachers in 'pgt' CATEGORY

2. List names of teachers in Hindi DEPARTMENT

3. List NAME, DEPARTMENT, HIREDATE of the teachers in ascending order of


HIREDATE

4. To count the number of the teachers in English DEPARTMENT

5. Select max(HIREDATE) from teachers

6. Select distinct (CATEGORY) from teachers

7. Select count(ID) from teachers where CATEGORY='pgt'

8. Select avg(SALARY), max(SALARY), min(SALARY) from teachers


QUERIES:-

QUERY 1:-
Select * from teachers where category=’pgt’;

QUERY 2:-
select name from teachers where department='hindi';

QUERY 3:-
select name, department, hiredate from teachers order by hiredate asc;

QUERY 4:-
select count(id) from teachers where department='english';

QUERY 5:-
select max(hiredate) from teachers;

QUERY 6:-
Select distinct(category) from teachers;

QUERY 7:-
Selecct count(id) from teachers where category=’pgt’;

QUERY 8:-
Select avg(salary),max(salary),min(salary) from teachers;

You might also like