2
PART-A-PYTHONPROGRAMS
1. PROGRAM-1:Write the program to find the given strings
palindrome or not.
AIM:
To write the program to find the given string is palindrome or
not.
SOURSE CODE-1
print("Palindromecheckingprogram")
s=input("Enter the string :")
s1=s[::-1]
ifs==s1:
print("Thegivenstring",s,"isapalindrome") else:
print("Thegivenstring",s,"isnotapalindrome")
PROGRAM-2:Write a program to create a phone contact book and
also to do search,update and delete contact.
AIM:
To write a program to create a phone contact book and also to
do search,update and delete contact.
3
SOURSE CODE-2
pb={}
def addcontact():
ans='y'
while ans=='y':
na=input("Entername:")
no=int(input("Entermobilenumber:"))
nc=str(no)
iflen(nc)==10:
pb[na]=no
print("Contactsavedsuccessfully") else:
print("[Link]")
continue
ans=input("Doyouwanttoaddanothercontact(y/n):")
def searchcontact():
na=input("Enterthenamewhichyouwanttosearch:") if na
in pb:
print("Mobilenumber:",pb[na]) else:
print("Namenotincontactbook")
def updatecontact():
na=input("Enterthenamewhichyouwanttoupdate:") if na
in pb :
no=int(input("Enterthenewnumber"))
nc=str(no)
iflen(nc)==10:
pb[na]=no
print("Contactnumberupdated")
else:
print("[Link].")
else:
print("Namenotincontactbook")
def deletecontact():
na=input("Enterthenamewhichyouwanttodeletethecontact:") if na in
pb:
del pb[na]
print("Contactdeleted")
else:
print("Namenotincontactbook")
4
while True:
print("Phonecontactbook")
print("1-toaddcontact\n2-tosearchcontact\n3-toupdate
contact\n4-to delete contact\n5-to quit")
ch=int(input("Enteryourchoice:")) if
ch==1:
addcontact()
elif ch==2:
searchcontact()
elif ch==3:
updatecontact()
elif ch==4:
deletecontact()
elif ch==5:
break
else:
print("[Link]")
continue
PROGRAM-3:Write a program to find the area of the shape sousing
module.
AIM:
To write a program to find the area of the shape sousing module.
SOURSE CODE-3
MODULECODE:MODULENAME:[Link]
def square(a):
returna*a
def rectangle(l,b):
return l*b
def triangle(b,h):
return b*h
def circle(r):
return3.14*r*r
def cube(a):
return 6*a**2
def cylinder(r,h):
return2*3.14*r*(r+h)
def cone(r,h):
return3.14*r*r+h
def sphere(r):
return4*3.14*r**2
5
MAIN PROGRAM:
import area
print("Areaoftheshapescalculatingprogram") while
True:
print("1-square\t2-rectangle\t3-triangle\t4-circle\n5-cube\t6-
cylinder\t7-cone\t8-sphere\t9-quit")
ch=int(input("Enteryourchoice:")) if
ch==1:
a=float(input("Entertheareavalue:"))
ar=[Link](a)
print("Theareaofthesquareis:",ar) elif
ch==2:
l=float(input("Enter the length value:"))
b=float(input("Enterthebreadthvalue:"))
ar=[Link](l,b)
print("Theareaoftherectangleis:",ar) elif
ch==3:
b=float(input("Enter the base value:"))
h=float(input("Entertheheightvalue:"))
ar=[Link](b,h)
print("Theareaoftherectangleis:",ar) elif
ch==4:
a=float(input("Entertheradiusvalue:"))
ar=[Link](a)
print("Theareaofthecircleis :",ar)
elif ch==5:
a=float(input("Entertheareavalue:"))
ar=[Link](a)
print("Theareaofthecubeis:",ar) elif
ch==6:
r=float(input("Entertheradiusvalue:"))
h=float(input("Entertheheightvalue:"))
ar=[Link](r,h)
print("Theareaofthecylinderis:",ar) elif
ch==7:
r=float(input("Entertheradiusvalue:"))
h=float(input("Entertheheightvalue:"))
ar=[Link](r,h)
print("Theareaoftheconeis:",ar) elif
ch==8:
a=float(input("Entertheradiusvalue:"))
ar=[Link](a)
6
print("Theareaofthesphereis:",ar) elif
ch==9:
break
else:
print("Invalidchoice")
continue
PROGRAM-4:Writearandomnumbergeneratorthatgenerates random
numbers between 1 and 6 (simulates a dice).
AIM:
To write a random number generator that generates random
numbersbetween1and6(simulates a dice).
SOURSE CODE-4
import random
print("Dice game ")
print("Gamestarts...")
ans='y'
whileans=='y':
print("Dicerolling .......... ")
s=[Link](1,6)
print("You got:",s)
ans=input("Doyouwanttorollagainthedice(y/n):")
print("See you again.. Bye ..... ")
OUTPUT:
Dicegame
Game starts...
Dicerolling....
You got: 5
7
Do you want to roll again the dice(y/n):y
Dice rolling....
Yougot:2
Do you want to roll again the dice(y/n):y
Dice rolling....
Yougot:2
Do you want to roll again the dice(y/n):y
Dice rolling....
Yougot:6
Do you want to roll again the dice(y/n): n
See you again.. Bye…
print()
b=[Link]()
[Link]()
FILE CONTENT:
I am a computer science student.
I am learning python programming.