Professional Documents
Culture Documents
No Topic Page
number
1 Arithmetic Operations 1-2
2 Perfect Number 3
3 Armstrong Number 4
4 Palindrome Number 5
6 Floyd’s Triangle 8
CODE:
x=int(input("enter number 1:"))
y=int(input("enter number 2:"))
print("""
A-Addition
B-Subtraction
C-Multiplication
D-Division
E-Floor division
F-Remainder
G-Exponentiation""")
ans="y"
while ans=="y":
n=input("Enter the number of your choise: A or B or C or D or E or F or G.")
if n=="A":
print(x+y)
elif n=="B":
print(x-y)
elif n=="C":
print(x*y)
elif n=="D":
print(x/y)
elif n=="E":
print(x//y)
elif n=="F":
print(x%y)
elif n=="G":
print(x**y)
else:
print("INVALID ALPHABET ENTERED")
ans=input("Do you want to continue?.ANS with y(yes) or n(no)")
OUTPUT:
2
RESULT:
The above program was executed and output obtained.
2
EXP NO:2 PERFECT NUMBER
AIM:
To write a program to check whether the given number is a perfect number or not.
CODE:
n=int(input("Enter any number:"))
cs=0
for i in range(1,n):
if n%i==0:
cs=cs+i
if cs==n:
print("Yes ,the given number is a perfect number")
else:
print("No,the given number is not a perfect number")
OUTPUT:
RESULT:
The above program was executed and output obtained.
CODE:
n=int(input("Enter any number:"))
a=str(n)
l=len(a)
cs=0
for i in a:
cs=cs+int(i)**l
if cs==n:
print("Yes ,the given number is an armstrong number")
else:
print("The given number is not an armstrong number")
OUTPUT:
RESULT:
The above program was executed and output obtained.
CODE:
def Palindrome(s):
l1=list(s)
l2=list(s)
l2.reverse()
if l1==l2:
return True
else:
return False
s=input("Enter a String:")
f=Palindrome(s)
if f==True:
print("The String",s,"is Palindrome")
else:
print("The String",s,"is Not a Palindrome")
OUTPUT:
RESULT:
The above program was executed and the output obtained.
OUTPUT:
2
RESULT:
The above program was executed and the output obtained.
2
To write a program to print the Floyd’s triangle pattern.
CODE:
n=int(input('enter no of rows'))
a=1
for i in range(1, n+1):
for j in range(1,i +1):
print(a, end = ' ')
a=a+1
print()
OUTPUT:
RESULT:
The above program was executed and the output obtained.
2
To write a program to modify the elements of a list.
CODE:
n=eval(input('Enter a list:'))
o=1
while o>0:
x=eval(input('Enter the element to be searched for and modified:'))
y=eval(input('Enter the element to be replaced:'))
n[n.index(x)]=y
print("The modified list is",n)
s=input('do you want to continue(y/n)')
if(s=='y'):
pass
else:
print("The program has now come to an end.")
break
print(n)
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
2
To write a program to count the number of even and odd numbers in a tuple.
CODE:
n=eval(input('Enter a tuple which consists of numbers only:'))
odd=0
eve=0
for i in n:
if i%2==0:
eve+=1
else:
odd+=1
print('Number of odd numbers:',odd)
print('Number of even numbers:',eve)
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
To write a program to count the number of vowels in a string.
2
CODE:
n=input('Enter any string of your choice:')
d={}
x=['a','i','o','e','u','A','E','I','O','U']
for i in n:
if i in x:
d[i]=n.count(i)
print(d)
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
To write a program to print random numbers between 10 and 100.
2
CODE:
import random
print(random.randint(10,100))
OUTPUT:
RESULT:
The above program was executed and the output obtained.
EXP NO:11 COUNTING THE NUMBER OF TIMES THE WORD ‘MY’ HAS
OCCURRED IN A GIVEN TEXT FILE
AIM:
To write a program to count the number of times the work ‘MY’ occurred in a given text file.
CODE:
2
def displayMy():
num=0
f=open("C:\\Users\\Student\\Documents\\STORY.txt","r")
N=f.read()
M=N.split()
for x in M:
if x=="MY":
print(x)
num=num+1
f.close()
print("Count of MY in file:",num)
displayMy()
OUTPUT:
RESULT:
The above program was executed and the output obtained.
CODE:
myfile=open("C:\\Users\\Student\\Desktop\\inba\\New folder inban\\record\\m.txt","r")
dc=0
uc=0
2
x = myfile.read()
for i in x:
if i.isupper()==True:
uc=uc+1
elif i.isdigit()==True:
dc=dc+1
continue
print("The number of digits present-:",dc)
print("The number of uppercase characters present-:",uc)
myfile.close()
OUTPUT:
RESULT:
The above program was executed and the output obtained.
CODE:
import pickle
stu={}
stufile=open('Stu.dat','ab')
2
ans='y'
while ans =='y':
rno=int(input("Enter roll number:"))
name=input("Enter name:")
pmarks=float(input("Enter marks in physics:"))
cmarks=float(input("Enter marks in chemistry:"))
mmarks=float(input("Enter marks in mathematics:"))
stu['Rollno']=rno
stu['Name']=name
stu['Marks in physics']=pmarks
stu['Marks in chemistry']=cmarks
stu['Marks in mathematics']=mmarks
pickle.dump(stu,stufile)
ans=input("Want to append more records?(y/n)...")
stufile.close()
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
To write a program to open a binary file and search for records with roll no as 12,24.
CODE:
import pickle
stu={}
found=False
fin=open('Stu.dat','rb')
searchkeys=[12,24]
try:
2
print("Searching........")
while True:
stu=pickle.load(fin)
if stu['Rollno'] in searchkeys:
print(stu)
found=True
except EOFError:
if found==False:
print("No such records found in the file")
else:
print("Search successful.")
fin.close()
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
To write a program to create a CSV file to enter the product details.
CODE:
import csv
n=int(input("Enter how many product record you want to create?"))
fh=open("Student.csv","w")
stuwriter=csv.writer(fh)
stuwriter.writerow(['ProductID','Product Name','Product Price'])
for i in range(n):
print("Student record:",(i+1))
2
productid=int(input("Enter product ID:"))
productname=input("Enter product name:")
productprice=float(input("Enter product price:"))
sturec=[productid,productname,productprice]
stuwriter.writerow(sturec)
fh.close()
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
To write a program to perform all stack operations.
CODE:
def Push(it):
global top
if S==[ ]:
top=0
S.append(it)
else:
top=top+1
2
S.append(it)
print("Element added successfully into Stack")
def Pop( ):
global top
if S==[ ]:
print("Underflow occurs. No Element to display")
else:
e=S.pop()
print("Deleted Element is:", e)
if S==[ ]:
top=None
else:
top=top-1
def Display( ):
if S==[ ]:
print("Stack is Empty. No Element to display")
else:
print("Element in the Stack are:")
t=top
while t>=0:
print(S[t], end='->')
t=t-1
print("!!!")
def Peek( ):
if S==[ ]:
print("Stack is Empty. No Element to display")
else:
print("Top Most Element in the Stack is:", S[top])
S=[ ]
top=None
while True:
ch=int(input("Enter 1 to insert, 2 to delete, 3 to display, 4 to peek & 5 to exit:"))
if ch==1:
it=int(input("Enter an element to insert:"))
Push(it)
elif ch==2:
Pop( )
elif ch==3:
Display( )
elif ch==4:
Peek( )
elif ch==5:
break
else:
print("Enter valid choice between 1 and 5")
2
OUTPUT:
RESULT:
The above program was executed and the output obtained.
AIM:
To write a program to print the vowels in a string using stacks concept.
CODE:
def push(n):
global top
for i in n:
if i in'AEIOUaeiou':
s.append(i)
top=len(s)-1
print('Vowels in the stack are :')
t=top
while t>=0:
2
print(s[t], end=',')
t=t-1
print("!!!")
s=[]
top=None
n=input("Enter a string to be added:")
push(n)
OUTPUT:
RESULT:
The above program was executed and the output obtained.
QUERIES:
1. create table Student(Sno int, AdmNo int, Name varchar(20), City varchar(30), Math
int, Physics int, Chemistry int);
2. select * from Student where Math>90;
3. select * from Student where Name like "A%";
4. select * from Student where Name like " E%";
5. select * from Student order by Name desc;
6. update Student set Physics = Physics + 2 where Physics = 80;
7. select * from Student where City = "Coimbatore";
8. alter table Student modify Name varchar(40);
9. select sum(Math) as "Total", avg(Math) as "Average" from Student;
10. select max(Physics) as "Maximum" from Student;
11. delete from Student;
12. drop table Student;
13. show databases;
14. show tables;
15. desc Student;
OUTPUT:
2)
3)
2
4)
5)
7)
9)
10)
2
15)
RESULT:
The above program was executed and the output obtained.
CODE:
i. select * from Student,library where Student.SNo=library.SNo;
ii. select Name from Student,library where Student.SNo=library.Sno and ReturnStatus=”No”;
iii. select Name,Bid,Bname,IssueDate from Student,library where Student.SNo=library.Sno order by
IssueDate;
2
iv. update library set ReturnStatus=”Yes” where IssueDate
OUTPUT:
i)
ii)
iii)
iv)
v)
RESULT:
The above program was executed and the output obtained.
2
EXP NO:20 SQL CONNECTIVITY
AIM:
Write a Python program to connect the Student table to perform the following operations.
i. Insert a record
ii. Display the entire content of the table
iii. Delete a record
iv. Update a record
CODE:
import mysql.connector as mc
mycon = mc.connect(host="localhost", user="root", passwd="123456", database="Student") mycursor =
mycon.cursor()
def reg():
2
sno = int(input("Enter serial number:"))
2
def upcity():
nom = input("Enter the Student number to update the city")
if n == 1:
register()
elif n == 2:
view()
elif n == 3:
dele()
elif n == 4:
upcity()
else:
print("Choose within the given range(1-4)")
ch = input("Do you want to continue?(y/n)")
OUTPUT:
i)Insert a record
28
ii)Display the contents of the table
iii)Delete a record
29
iv)Update a record
RESULT:
The above program was executed and the output obtained.
30
1