Professional Documents
Culture Documents
------------------------------------------------------------------------
# PALINDROME
# PROGRAM 1
------------------------------------------------------------------------
# PROGRAM 2
else:
print("it is not valid input")
------------------------------------------------------------------------
# PROGRAM 3
a=int(input("Enter the prime number range"))
for i in range(2,a):
for j in range(2,a):
if i%j==0:
break
if i==j:
print(i,end=",")
------------------------------------------------------------------------
# PROGRAM 4
a="computer"
for i in range(0,len(a),i+2):
print(a[i])
------------------------------------------------------------------------
# PROGRAM 5
a=[1,2,3,4,5,6]
sum=0
for i in a:
sum+=i
print(sum)
------------------------------------------------------------------------
# PROGRAM 6
a=[10,2]
sum=1
for i in a:
sum*=i
print(sum)
------------------------------------------------------------------------
# PROGRAM 7
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=int(input("Enter the array elements"))
lst.append(ele)
print(lst)
print("product values of the list elements ")
sum=1
for i in lst:
sum*=i
print(sum)
print ("the sum of the list elements")
sum=0
for i in lst:
sum+=i
print(sum)
------------------------------------------------------------------------
# PROGRAM 8
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=int(input("Enter the array elements"))
lst.append(ele)
print(lst)
lst.sort()
print("The largest number is:",lst[-1])
------------------------------------------------------------------------
# PROGRAM 9
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=int(input("Enter the array elements"))
lst.append(ele)
print(lst)
m=lst[0]
for i in lst:
if i>m:
m=i
print(m)
------------------------------------------------------------------------
# PROGRAM 10
def MAX(list):
m=list[0]
for i in list:
if i>m:
m=i
return m
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=int(input("Enter the array elements"))
lst.append(ele)
print(lst)
d=MAX(lst)
print(d)
------------------------------------------------------------------------
# PROGRAM 11
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=input("Enter the array elements")
lst.append(ele)
print(lst)
c=0
for i in lst:
if (i[0]==i[-1]):
c=c+1
print(c)
------------------------------------------------------------------------
# PROGRAM 12
def MIN(list):
m=list[0]
for i in list:
if i<m:
m=i
return m
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=int(input("Enter the array elements"))
lst.append(ele)
print(lst)
d=MIN(lst)
print(d)
------------------------------------------------------------------------
# PROGRAM 13
------------------------------------------------------------------------
# PROGRAM 14
------------------------------------------------------------------------
# PROGRAM 15
def secondlargestelement(list):
list.sort()
return list[-2]
lst=[]
a=int(input("Enter the range of list elements"))
for i in range (0,a):
ele=int(input("Enter the array elements"))
lst.append(ele)
print(lst)
E=[]
O=[]
for i in range(0,a):
if i%2==0:
e=lst[i]
E.append(e)
else:
o=lst[i]
O.append(o)
print(E)
print(O)
Evenl=secondlargestelement(E)
Oddl=secondlargestelement(O)
print(Evenl)
print(Oddl)
Sum=Evenl+Oddl
print("Sum",Sum)
------------------------------------------------------------------------
# PROGRAM 16
file=open('Mypythonfile.txt','x')
------------------------------------------------------------------------
# PROGRAM 17
fp=open("Mypythonfile.txt","w")
fp.write("I am writing sentence 4")
fp.close()
------------------------------------------------------------------------
# PROGRM 18
file=open('Mypythonfile.txt','r')
------------------------------------------------------------------------
# PROGRAM 19
fp=open('helloworld.txt','x')
------------------------------------------------------------------------
# PROGRM 20
fp=open('helloworld.txt','w')
fp.write("Hello World")
------------------------------------------------------------------------
# PROGRAM 21
numberofwords=0
with open(r'helloworld.txt','r') as fp:
data=fp.read()
line=data.split()
numberofwords +=len(line)
print(numberofwords)
------------------------------------------------------------------------
# PROGRAM 22
character=0
numberofwords=0
with open(r'helloworld.txt','r') as fp:
data=fp.read()
line=data.split()
numberofwords +=len(line)
character += len(numberofwords)
print(numberofwords)
print(character)
------------------------------------------------------------------------
# PROGRAM 23
import random
lst=[]
n=int(input("Enter the range of list :"))
for i in range(0,n):
ele=int(input("Enter the list element :"))
lst.append(ele)
print(lst)
d=random.choice(lst)
print(d)
------------------------------------------------------------------------
# PROGRAM 24
import random
set=('Elon',123,'Musk',4.5,567)
print(random.choice(set))
------------------------------------------------------------------------
# PROGRAM 25
import random
dict = {
"Apple": ["Green", "Healthy", "Sweet"],
"Banana": ["Yellow", "Squishy", "Bland"],
"Steak": ["Red", "Protein", "Savory"]
}
random_value=random.choice(list(dict.values()))
print ("Random_value : ",random_value)
random_key=random.choice(list(dict.keys()))
print ("Random_key : ",random_key)
random_item=random.choice(list(dict.items()))
print ("Random_item : ",random_item)
------------------------------------------------------------------------
# PROGRAM 26
import os,random
print("\nSelect a random file from a directory.:")
print(random.choice(os.listdir("/")))
------------------------------------------------------------------------
# PROGRAM 27
res=""
inp=input("Enter the string")
for i in range(0,len(inp),2):
for j in range(int(inp[i+1])):
res=res+inp[i]
print(res)
------------------------------------------------------------------------
# PROGRAM 28
class Dog:
def __init__(self,name,age):
self.name=name
self.age=age
def bark(self):
print(f"{self.name} is barking!")
def Age(self):
print(f"{self.age} years old!")
def Detail(self):
print(f"Dog name is :{self.name}")
print(f"Dog age is :{self.age}")
my_dog=Dog("Buddy",3)
my_dog.bark()
my_dog.Age()
dog=Dog("Rose",5)
dog.Detail()
------------------------------------------------------------------------
# PROGRAM 29
class Vehicle:
def __init__(self,speed,Mileage,name):
self.speed=speed
self.Mileage=Mileage
self.name=name
model=Vehicle(220,50,"ferrari")
print(f"The Vehicle name is :{model.name},and its top speed is: {model.speed} ,and
its Milage:{model.Mileage}")
------------------------------------------------------------------------
# PROGRAM 30
class areaofcircle:
def __init__(self,pi,r):
self.pi=pi
self.r=r
self.t=pi*r*r
def area(self):
print(f"Area of the circle :{self.t}")
circle_area=areaofcircle(3.14,10)
circle_area.area()
class circum:
def __init__(self,pi,r):
self.pi=pi
self.r=r
self.t=pi*r*2
def cir(self):
print(f"#circum of the circle :{self.t}")
circle_circum=circum(3.14,4)
circle_circum.cir()
------------------------------------------------------------------------
# PROGRAM 31
#inheritance
class Scl:
def __init__(self,name,regno):
self.name=name
self.regno=regno
class Student(Scl):
def Details(self,atten,bldg):
self.atten=atten
self.bldg=bldg
print(f"the student name is {self.name}and student bloodgroup is
{self.bldg}")
my_detail=Student("vijay",610722)
my_detail.Details(60,"o+")
------------------------------------------------------------------------
# PROGRAM 32
def Display(self):
print(f"the student name is {self.name}and student bloodgroup is
{self.year}")
my_detail=Student("vijay",61,2019)
my_detail.print()
my_detail.Display()
------------------------------------------------------------------------
# PROGRAM 33
class Vehicle:
def __init__(self, seating_capacity):
self.seating_capacity = seating_capacity
def fare(self):
return self.seating_capacity * 100
class Bus(Vehicle):
def __init__(self, seating_capacity):
super().__init__(seating_capacity)
def fare(self):
original_fare = super().fare()
return original_fare + (0.1 * original_fare)
my_bus = Bus(50)
------------------------------------------------------------------------
# PROGRAM 34
class Employee:
def __init__(self,emp_id,emp_name,emp_department):
self.emp_id=emp_id
self.emp_name=emp_name
self.emp_department=emp_department
def calculate_emp_salary(self):
def emp_assign_department(self):
def print_employee_Detail(self):
------------------------------------------------------------------------
INSTALL AND IMPORT NUMPY
# PROGRAM 35
import numpy as np
# In[1]:
a=np.array(23)
print(a)
# In[2]:
print(a.ndim)
# In[3]:
# In[10]:
print(a.shape)
# In[4]:
print(type(a))
# In[12]:
print(a.size)
# In[5]:
b=np.array([[1,2],[3,4]])
print(b)
# In[6]:
print(type(b))
# In[7]:
print(b.shape)
print(b.ndim)
# In[8]:
print(b.size)
# In[9]:
#3_D array
c=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
print(c)
#shape
print(c.shape)
#size
print(c.size)
#type
print(type(c))
#dimensional
print(c.ndim)
# In[10]:
# In[11]:
# In[13]:
# In[15]:
# In[16]:
# In[17]:
list=[1,2,3,4,5,6,7,8]
tuple=(8,7,6,5,4,3,2,1)
a=np.array(list)
b=np.array(tuple)
print(a)
print(b)
# In[18]:
list=[1,2,3,4,5,6,7,8]
tuple=([8,7,6],[5,4,3])
a=np.array(list)
b=np.array(tuple)
print(a)
print(b)
# In[19]:
a=np.array((10,20,30))
b=np.array((40,50,60))
c=np.column_stack((a,b))
print(c)
-------------------------------------------------------------------------
MYSQL CONNECTOR
# PROGRAM 36
# In[1]:
import mysql.connector
mydb=mysql.connector.connect(
host= " localhost",
user="root",
password="Gceb@6107",
database="gceb")
print(mydb)
# In[2]:
mycursor=mydb.cursor()
mycursor.execute("create database gceb")
# In[26]:
mycursor.execute("show database")
for x in range(mycursor):
print(x)
# In[3]:
mycursor.execute("use gceb")
# In[4]:
# In[5]:
mycursor=mydb.cursor(buffered="true")
col="insert into students (std_id,std_fname,std_lname)values (%s,%s,%s)"
val=[(102,"ckon","dkon"),(103,"ekon","fkon"),(104,"gkon","hkon")]
mycursor.executemany(col,val)
mydb.commit()
print(mycursor.rowcount,"record inserted")
# In[6]:
# In[7]:
mycursor=mydb.cursor(buffered="true")
mycursor.execute("select *from students")
myresult=mycursor.fetchone()
for x in myresult:
print(x)
# In[8]:
# In[9]: