Computer Programs Python
Computer Programs Python
Computer Programs Python
PRACTICAL RECORD
PYTHON PROGRAMS
TEACHER'
PAGE
S.NO. DATE CONTENTS S
NO
INITIAL
AIM:
To write a Python program to input and display the welcome message.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :Enter the input and display a welcome message.
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
print(a)
OUTPUT:
PROGRAM NO : 2
DATE :
AIM:
To write a Python program to input and display the larger and smaller number.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to input two numbers and display larger, smaller number
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
if a>b:
else:
OUTPUT:
PROGRAM NO :3
DATE :
AIM:
To write a Python program to input three numbers and display largest and
smallest number.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to input three numbers and display largest, smallest number.
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
if y>z:
print(x,'>',y,'>',z)
print(x,'>',z,'>',y)
if z>x:
print(y,'>',z,'>',x)
else:
print(y,'>',x,'>',z)
else:
if y>x:
print(z,'>',y,'>',x)
else:
print(z,'>',x,'>',y)
LOOPS
AIM:
To write a Python program to generate patterns using nested loops
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to generate patterns using nested loops
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
#4.generate the patterns using nested loops:
#a.fori in range(1,6):
for j in range(1,i+1):
print("*",end="")
print()
for j in range(1,i+1):
print(j,end="")
print()
for j in range(65,65+i):
print(chr(j),end='')
print()
OUTPUT:
PROGRAM NO :5
DATE :
AIM:
To write a Python program to print the sum of following series
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to input the value of n and x and print the sum of following series. Step 5 :
Print the result.
Step 6 : Stop.
PROGRAM CODE:
#5.write a program to input the value of n and x and print the sum of
following series:
#a.1+x+x^2+x^3+...+x^n
s=0
fori in range(n+1):
s+=x**i
a=+1
s=0
for z in range(n+1):
term=(x**z)*a
s+=term
a*=-1
#c.x+(x^2)/2-(x^3)/3+(x^4)/4-...+(x^n)/n
sign = +1
a=x
s=x
fori in range(1,n+1):
s+=(x**i)/n
sign*=-1
s=x
sign = +1
for a in range(2,n+1):
f=1
fori in range(1,a+1):
f*=i
s +=term
term = ((x**a)*sign)/f
sign *=-1
AIM:
To write a Python program to determineperfect number, amstrong number or palindrome.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to determineperfect number, amstrong number or palindrome.
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
num=int(input('enter a number'))
wnum=num
rev=0
while (wnum>0):
dig=wnum%10
rev=rev*10+dig
wnum=wnum//10
if num==rev:
else:
summ=0
temp=num
while temp>0:
digit=temp%10
summ+=digit**3
temp//=10
if num==summ:
else:
summ=0
fori in range(1,n):
if (n%i==0):
summ=summ+i
ifsumm==n:
else:
AIM:
To write a Python program toprogram to insert a number and check whether it is a prime number
ornot
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to insert a number and check whether it is a prime number ornotStep 5 : Print
the result.
Step 6 : Stop.
PROGRAM CODE:
# Insert a number and check whether it is a prime number or not
fori in range(2,n):
ifn%i==0:
else:
break
OUTPUT:
PROGRAM NO :8
DATE :
AIM:
To write a Python program todisplay fabinnacci series
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to display fabinnacci series
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
# fabinacci series
i=int(input('enter the limit'))
x=0
y=1
z=1
print('fabinacci series\n')
print(x,y,end="")
while z<=i:
print(z,end="")
x=y
y=z
z=x+y
OUTPUT:
PROGRAM NO :9
DATE :
AIM:
To write a Python program tocompute the greatest common divisor and least common multiple
of two integers.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to compute the greatest common divisor and least common multiple of two
integers.
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
# input two integers and findhcf and lcm
a=int(input('enter a number'))
if a>b:
smallnum=b
else:
smallnum=a
fori in range(2,smallnum):
ifa%i==0 and b%i==0:
hcf=i
lcm=(a*b)/hcf
int(lcm)
OUTPUT:
PROGRAM NO :10
DATE :
AIM:
To write a Python program to count and display number of vowels, consonant, uppercase and
lowercase character in the string.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to count and display number of vowels, consonant, uppercase and lowercase
character in the string.
Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
consonant='bcdfghjklmnpqrstvwxyz'
lowercount=uppercount=vowelcount=consonantcount=0
n=len(line)
fori in line:
ifi.islower() :
lowercount+=1
elifi.isupper() :
uppercount+=1
fori in line:
ifi in vowel:
vowelcount+=1
elifi in consonant:
consonantcount+=1
AIM:
To write a Python program to.
PROGRAM ALGORITHM:
Step 1 : Start.
Step 2 : Get input number from the user.
Step 3 : Call user defined function by passing the number as an argument.
Step 4 :program to input a string and display whether it is a palindrome or not, convert the case
of characters into the string. Step 5 : Print the result.
Step 6 : Stop.
PROGRAM CODE:
# to check whether a word is polindrome or not,convert the case of characters into the
string.
n=len(string)
mid=n/2
if mid%2!=0:
mid+=1
else:
mid=n/2
a=int(mid)
rev=-1
fori in range(a):
if string[a]==string[rev]:
a+=1
rev-=1
elif string[a]!=string[rev]:
break
else :
a=string.upper()
b=string.lower()