Professional Documents
Culture Documents
Sishya School, Hosur: Practical File ON
Sishya School, Hosur: Practical File ON
Sishya School, Hosur: Practical File ON
PRACTICAL FILE
ON
PYTHON PROGRAMS
CLASS : XI
Bonafide Certificate
AIM
To write a python program to input a welcome message and display it.
ALGORITHM
Step 1: Start
Step 2: Get “name” as input from the user
Step 3: Get a welcome message form the user
Step 4: Display the name along with the message using print statement
Step 5: Stop
PROGRAM
name=input("Enter your name:")
message=input("Enter a Message:")
print(name,message)
Program Screenshot
OUTPUT
Case 1:
Case 2:
RESULT
Thus the python program to input a welcome message and display it is completed and
output is verified successfully.
Exp No : 2
Input two numbers and display the larger / smaller number.
Date :
AIM
To develop a python program to input two numbers and display the larger or smaller
number
ALGORITHM
Step 1: Start
Step 2: Get two integers numbers “num1” and “num2” as input from the user
Step 3: Use conditional Statement
if num1> num2:
Display “Num1 is Greatest” and “Num2 is Smallest”
else:
Display “Num2 is Greatest” and “Num1 is Smallest”
Step 4: Stop
PROGRAM
#Get two numbers as input
num1=int(input("Enter the First Number:"))
num2=int(input("Enter the Second Number:"))
Program Screenshots
OUTPUT
Case 1
Case 2
RESULT
Thus the program to input two numbers and display the greatest or smallest is completed
and output is verified successfully.
Exp No : 3
Input three numbers and display the largest number.
Date :
AIM
To implement a python program to input three numbers and display the largest number
ALGORITHM
Step 1: Start
Step 2: Get three numbers “num1”, “num2” and “num3” as integer input from the user
Step 3: Use conditional statement
if (num1>num2) and (num1>num3):
Display “num1” is the largest
elif(num2>num3):
Display “num2” is the largest
else:
Display “num3” is the largest
Step 4: Stop
PROGRAM
#Get three numbers as input
num1=int(input("Enter the First Number:"))
num2=int(input("Enter the Second Number:"))
num3=int(input("Enter the Third Number:"))
Case 2
Case 3
RESULT
Thus the program to find the largest of three numbers is completed and output is verified
successfully.
Exp No : 4
Input three numbers and display the smallest number.
Date :
AIM
To implement a python program to input three numbers and display the smallest number
ALGORITHM
Step 1: Start
Step 2: Get three numbers “num1”, “num2” and “num3” as integer input from the user
Step 3: Use conditional statement
if (num1<num2) and (num1<num3):
Display “num1” is the smallest
elif(num2<num3):
Display “num2” is the smallest
else:
Display “num3” is the smallest
Step 4: Stop
PROGRAM
#Get three numbers as input
num1=int(input("Enter the First Number:"))
num2=int(input("Enter the Second Number:"))
num3=int(input("Enter the Third Number:"))
Program screenshots
OUTPUT
Case 1
Case 2
Case 3
RESULT
Thus the program to find the smallest of three numbers is completed and output is verified
successfully.
Exp No : 5
Given two integers x and n, compute 𝑥n.
Date :
AIM
To implement a python program to get two integers and calculate its power
ALGORITHM
Step 1: Start
Step 2: Get two integer values “x” and “n” from the user
Step 3: Calculate xn using the exponent operator
Cal=x**n
Step 4: Display “Cal”
Step 5: Stop
PROGRAM
#Get x and n as input
x=int(input("Enter the Value of x:"))
n=int(input("Enter the Value of n:"))
#Use exponent operator
Cal=x**n
print(x,"power",n,"is:",Cal)
Program Screenshot
OUTPUT
RESULT
Thus the program to calculate xn is implement and output is verified successfully.
Exp No : 6 Write a program to input the value of x and n and print the sum of the
Date : following series: 1+x+x2+x3+x4+ ............xn
AIM
To implement the series 1+x+x2+x3+x4+ ............xn .
ALGORITHM
Step 1: Start
Step 2: Read the values of “x” and “n” from the user
Step 3: Initialize sum0
Step 4: Calculate
for i in range(n+1):
sum+=x**a
Step 5: Display the sum
Step 6: Stop
PROGRAM
x=int(input("Enter the value of x:"))
n=int(input("Enter the value of n:"))
sum=0
for i in range(n+1):
sum+=x**i
print("Sum of the series is:",sum)
Program Screenshot
OUTPUT
Case 1
Case 2:
RESULT
Thus the series is implemented and output is verified.
Exp No : 7 Write a program to input the value of x and n and print the sum of the
Date : following series: 1-x+x2-x3+x4- ............xn
AIM
To implement the series 1-x+x2-x3+x4- ............xn .
ALGORITHM
Step 1: Start
Step 2: Read the values of “x” and “n” from the user
Step 3: Initialize sum0
Step 4: Initialize a variable sign+1
Step 5: Calculate
for i in range(n+1):
term(x**a)*sign
sum+=term
sign*=-1
Step 6: Display the sum
Step 7: Stop
PROGRAM
x=int(input("Enter the value of x:"))
n=int(input("Enter the value of n:"))
sum=0
sign=+1
for i in range(n+1):
term=(x**i)*sign
sum+=term
sign*=-1
print("Sum of the series is:",sum)
Program Screenshot
OUTPUT
Case 1
Case 2
RESULT
Thus the series is implemented and output is verified
Exp No : 8 Write a program to input the value of x and n and print the sum of the
𝑥2 𝑥3 𝑥𝑛
Date : following series: 𝑥 + − +⋯
2! 3! 𝑛!
AIM
𝑥2 𝑥3 𝑥𝑛
To implement the series 𝑥 + − +⋯
2! 3! 𝑛!
ALGORITHM
Step 1: Start
Step 2: Read the values of “x” and “n” from the user
Step 3: Initialize sumx
Step 4: Initialize a variable sign+1
Step 5: Calculate using nested for loop
for i in range(2,n+1):
f1
Step 6: for j in range(1,i+1):
f*=i
term((x**a)*sign)/f
sum+=term
sign*=-1
Step 6: Display the sum
Step 7: Stop
PROGRAM
x=int(input("Enter the value of x:"))
n=int(input("Enter the value of n:"))
sum=x
sign=+1
for i in range(2,n+1):
f=1
for j in range(1,i+1):
f*=j
term=((x**i)*sign)/f
sum+=term
sign*=-1
print("Sum of the series is:",sum)
Program Screenshot
OUTPUT
RESULT
Thus the series is implemented and output is verified
Exp No : 9
Determine whether a number is a perfect number or not
Date :
AIM
To develop a python program to find whether a given number is perfect or not.
ALGORITHM
Step 1: Start
Step 2: Get “n” as integer value from the user
Step 3: Use for loop to iterate over the range
for i in range(1,n):
Step 4: Use conditional statements
if(n%i==0):
Display “It is a perfect Number”
else:
Display “It is not a perfect Number”
Step 5: Stop
PROGRAM
n=int(input("Enter a number:"))
sum=0
for i in range(1,n):
if(n%i==0):
sum=sum+i
if(sum==n):
print("The number is perfect")
else:
print("The number is not perfect")
Program Screenshot
OUTPUT
Case 1:
Case 2:
RESULT
Thus the program to check whether the given number is a perfect or not is completed and
output is verified successfully.
Exp No : 10 Write a program to check whether a given number is an Armstrong
Date : number or not
AIM
To implement a python program to check whether a given number is an Armstrong number
or not.
ALGORITHM
Step 1: Start
Step 2: Get “n” as integer value from the user
Step 3: Initialize sum 0
Step 4: Use while loop to iterate over the range
while (temp>0)
Step 5: Use conditional statements
if(num==sum):
Display “It is an armstrong Number”
else:
Display “It is not an armstrong Number”
Step 6: Stop
PROGRAM
n=int(input("Enter a Number:"))
sum=0
temp=n
while(temp>0):
digit=temp%10
sum+=digit**3
temp//=10
if(n==sum):
print("It is an Armstrong Number")
else:
print("It is not an Armstrong Number")
Program Screenshots
OUTPUT
Case 1:
Case 2:
RESULT
Thus the python program to check whether a given number is an Armstrong
number or not is completed and output is verified.
Exp No : 11 Write a program to check if a given number is a palindrome number or
Date : not
AIM
To implement a python program to check if a given number is a palindrome number or not
ALGORITHM
Step 1: Start
Step 2: Get integer “num” as user input
Step 3: Initialize rev0
Step 4: Use while loop to iterate
While(rnum>0)
Step 5: Use conditional statements
if(num==rev):
Display “The number is a palindrome”
else:
Display “The number is not a palindrome”
Step 6: Stop
PROGRAM
num=int(input("Enter a Number:"))
rnum=num
rev=0
while(rnum>0):
dig=rnum%10
rev=rev*10+dig
rnum=rnum//10
if(num==rev):
print("The number is palindrome")
else:
print("The number is not palindrome")
Program Screenshot
OUTPUT
Case 1
Case 2
RESULT
Thus the python program to check whether the given number is a palindrome or not is
completed and output is verified successfully
Exp No : 12 Input a number and check if the number is a prime or composite
Date : number.
AIM
To implement a python program to input a number and check whether the number is prime
or composite
ALGORITHM
Step 1: Start
Step 2: Input a number “n” as integer from user
Step 3: Check whether the number is greater than 1
if n>1:
Step 4: Use for loop to iterate and check whether the number is divisible
for i in range(2,n):
Step 5: Check
if n%i==0: then Display “The number is Composite”
else, Display “The number is prime”
Step 6: Use if condition
elif n==0 or n==1:
print “The number is neither Prime nor Composite”
Step 7: Stop
PROGRAM
n=int(input("Enter the Number:"))
if n>1:
for i in range(2,n):
if n%i==0:
print(n,"is a Composite Number")
break
else:
print(n, "is a Prime Number")
elif n==0 or n==1:
print(n,"is neither Prime nor Composite")
else:
print(n,"is a Prime Number")
Program Screenshots
OUTPUT
Case 1
Case 2
Case 3
RESULT
Thus the program on check whether the given is prime or composite is executed
successfully and output is verified.
Exp No : 13
Display the terms of a Fibonacci series.
Date :
AIM
To implement a python program to display the terms of a Fibonacci series
ALGORITHM
Step 1: Start
Step 2: Get “t” as integer from the user as input
Step 3: Initialize first0 and second0
Step 4: Iterate the following statements till “t”
for i in range(2,t):
next=first+second
Step 5: Print the values
Step 6: Stop
PROGRAM
t=int(input("Enter the Number of terms:"))
first=0
second=1
print("Fibbonacci Series")
print("-----------------")
print(first,",",second,end=",")
for i in range(2,t):
next=first+second
print(next,end=",")
first=second
second=next
Program Screenshot
OUTPUT
RESULT
Thus the program to display the Fibonacci series is completed and output is verified.
Exp No : 14 Compute the greatest common divisor and least common multiple of
Date : two integers.
AIM
To develop a program to find the GCD and LCM of two numbers.
ALGORITHM
Step 1: Start
Step 2: Get two value x and y as integer as user input
Step 3: Check smaller number from x and y using the condition
if x>y:
smallery
else:
smallerx
Step 4: calculate LCM by using the formula
lcm(x*y)/hcf
Step 5: Display LCM and HCF
Step 6: Stop
PROGRAM
x=int(input("Enter First Number:"))
y=int(input("Enter Second Number:"))
if x>y:
smaller=y
else:
smaller=x
for i in range(1,smaller+1):
if((x%i==0)and(y%i==0)):
hcf=i
lcm=(x*y)/hcf
print("The HCF of ",x,"and",y,"is:",hcf)
print("The LCM of ",x,"and",y,"is:",lcm)
Program Screenshot
OUTPUT
RESULT
Thus the program to find the GCD and LCM of two numbers is executed and output is
verified successfully.
Exp No : 15 Count and display the number of vowels, consonants, uppercase,
Date : lowercase characters in string
AIM
To develop a python program to count and display the number of vowels, consonants,
uppercase and lowercase characters in string
ALGORITHM
Step 1: Start
Step 2: Get a string input from the user and store it in “str”
Step 3: Initialize v0,c0,u0 and l0
Step 4: Calculate length of the string using inbuilt functions
len(str)
Step 5: Use conditional statements and check whether the character is vowel
Step 6: Increment the value ‘v’ by 1. Else increment the value ‘c’ by 1.
Step 5: Display the results
Step 6: Stop
PROGRAM
str1=input("Enter a string:")
v,c,u,l=0,0,0,0
for i in range(0,len(str1)):
ch=str1[i]
if (ch=='a' or ch=='e' or ch=='i'or ch=='o'or ch=='u' or ch=='A'or ch=='E'or ch=='I'or
ch=='O'or ch=='U'):
v+=1
else:
c+=1
for ch in str1:
if ch>='A' and ch<='Z':
u+=1
if ch>='a' and ch<='z':
l+=1
print("Vowels :",v)
print("Consonents :",c)
print("Uppercase :",u)
print("Lowercase :",l)
Program Screenshots
OUTPUT
RESULT
Thus the program to Count and display the number of vowels, consonants, uppercase,
lowercase characters in string is executed and output is verified.
Exp No : 16
Input a string and determine whether it is a palindrome or not
Date :
AIM
To develop a python program to check whether the given string is a palindrome or not.
ALGORITHM
Step 1: Start
Step 2: Get a string “str1” as input from the user
Step 3: Use backward indexing to reverse a string
Step 4: Check if (str1==str1[::-1]), if True then
Display “It is a palindrome”
else:
Display “It is not a palindrome”
Step 5: Stop
PROGRAM
import string
str1=input("Enter a String:")
if (str1==str1[::-1]):
print("It is a palindrome")
else:
print("It is not a palindrome")
Program Screenshot
OUTPUT
Case 1
Case 2
RESULT
Thus the program to check whether the given string is a palindrome or not is executed and
output is verified successfully.
Exp No : 17
Convert the case of characters in a string
Date :
AIM
To implement a python program to convert the case of characters in a string.
ALGORITHM
Step 1: Start
Step 2: Get a string input from the user and store in “str1”
Step 3: Use inbuilt string functions to convert the case of characters
Step 4: Display the result
Step 5: Stop
PROGRAM
str1=input("Enter a String:")
print("Lower Case:",str1.lower())
print("Upper Case:",str1.upper())
print("Title Case:",str1.title())
print("Capitalize:",str1.capitalize())
print("Swap Case:",str1.swapcase())
Program Screenshot
OUTPUT
RESULT
Thus the program to convert the case of characters in a string is executed and output is
verified successfully.
Exp No : 18
Find the largest/smallest number in a list/tuple
Date :
AIM
To implement a python program to find the largest and smallest number in a list or tuple.
ALGORITHM
Step 1: Start
Step 2: Initialize a list/tuple of numbers
Step 3: Use inbuilt functions max() and min()
Step 4: Display the largest and smallest value
Step 5: Stop
PROGRAM
list1=[23,12,4,56,11,2]
tuple1=(15,12,6,89,99,1)
print("The maxmimum value in list is:",max(list1))
print("The minimum value in list is:",min(list1))
print("The maxmimum value in tuple is:",max(tuple1))
print("The minimum value in list is:",min(tuple1))
Program Screenshot
OUTPUT
RESULT
Thus the program to find the largest and smallest number in a list or tuple is executed and
output is verified successfully.
Exp No : 19 Input a list of numbers and swap elements at the even location with the
Date : elements at the odd location
AIM
To implement a python program to input a list of numbers and swap elements at the even
location with the elements at the odd location
ALGORITHM
Step 1: Start
Step 2: Create a empty list “L”
Step 3: Input the size of “N”
Step 4: Use for loop to iterate and append the elements to list L.
Step 5: Do L[i],L[i-1]=L[i-1],L[i]
Step 6: Display the swapped list
Step 7: Stop
PROGRAM
L=[]
N=int(input("Enter the Size of the list:"))
print("Enter the elements one by one")
for i in range(N):
E=int(input("->"))
L.append(E)
print("The given List is:")
print(L)
for i in range(1,N,2):
L[i],L[i-1]=L[i-1],L[i]
print("\n The List after swapping is :")
print(L)
Program Screenshot
OUTPUT
RESULT
Thus the program to input a list of numbers and swap elements at the even location with
the elements at the odd location is executed and output is verified successfully.
Exp No : 20
Input a list of elements, search for a given element in the list
Date :
AIM
To implement a python program to input a list of elements and search for a given element.
ALGORITHM
Step 1: Start
Step 2: Input a list of elements
Step 3: Calculate the length of the list using len() function
Step 4: Use if element==lst[i]:
Display “The element is found”
else:
Display “The element is not found”
Step 5: Stop
PROGRAM
lst=eval(input("Enter the list:"))
length=len(lst)
element=int(input("Enter the element to search:"))
for i in range(0,length):
if element==lst[i]:
print(element,"found at index",i)
break
else:
print(element,"not found in the list")
Program Screenshot
OUTPUT
Case 1
Case 2
RESULT
Thus the program to input a list of elements and search for a given element is executed and
output is verified successfully.
Exp No : 21 Create a dictionary with the roll number, name and marks of n students
Date : in a class and display the names of students who have marks above 75
AIM
To implement a python program to create a dictionary with user inputs and display the
names of students who have marks above 75
ALGORITHM
Step 1: Start
Step 2: Get “n” as user input
Step 3: Create an empty dictionary “result”
Step 4: Enter “rno”,”name” and “marks” as user input
Step 5: Use conditional statement
if result[student][1] > 75:
Display “Name of the student”
Step 6: Stop
PROGRAM
n = int(input("Enter number of students: "))
result = {}
for i in range(n):
print("Enter Details of student No.", i+1)
rno = int(input("Roll No: "))
name = input("Name: ")
marks = float(input("Marks: "))
result[rno] = [name, marks]
print(result)
# Display names of students who have got marks more than 75
for student in result:
if result[student][1] > 75:
print(result[student][0])
Program Screenshot
OUTPUT
RESULT
Thus the program to create a dictionary with user inputs and display the names of students
who have marks above 75 is executed and output is verified successfully.