Lab Report Fininshng Textmaker
Lab Report Fininshng Textmaker
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]
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
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.
1. List the name of persons who have obtained division 1 in ascending order.
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.
1. Display the SUR NAME, FIRST NAME, CITY of employees residing in Manjeri.
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.
5. To display the P_NAME and SUP_NAME, those are serving their product in
Mumbai or kolkatta.
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
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;