0% found this document useful (0 votes)
881 views

Class 11 Practical File 2023 - 2024

This document contains summaries of 10 Python programs written as part of a practical file. Each program is summarized in 1-3 sentences: 1. A program that takes user input of a greeting message and displays it. 2. A program that takes two numbers as input and displays the larger and smaller number. 3. A program that takes two numbers as input, adds them, and displays the sum. 4. A program that takes three numbers as input and displays the largest and smallest among them. 5. A program that generates a left triangle star pattern using nested loops. 6. A program that displays a left triangle number pattern using nested loops. 7. A program

Uploaded by

srainodu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
881 views

Class 11 Practical File 2023 - 2024

This document contains summaries of 10 Python programs written as part of a practical file. Each program is summarized in 1-3 sentences: 1. A program that takes user input of a greeting message and displays it. 2. A program that takes two numbers as input and displays the larger and smaller number. 3. A program that takes two numbers as input, adds them, and displays the sum. 4. A program that takes three numbers as input and displays the largest and smallest among them. 5. A program that generates a left triangle star pattern using nested loops. 6. A program that displays a left triangle number pattern using nested loops. 7. A program

Uploaded by

srainodu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

CLASS : XI PRACTICAL FILE

2023 - 2024

Ex.No : 1 DISPLAY WELCOME MESSAGE

Write a Python program to input a welcome message and display it.


Aim:
To write a Python program to input a welcome message and display it.
Algorithm:
Step 1: Input Greeting message by input ( )
Step 2: Print the entered message
Source Code:
msg=input("Enter Greeting Message:")
print("The Entered Message is:",msg)
Output:

Result:
Thus, the program was executed successfully and the output was verified

Ex.No : 2 DISPLAY LARGER AND SMALLER NUMBER


Input two numbers and display larger and smaller number
Aim:
To write a Python program to input two numbers and display the larger and smaller
number.
Algorithm:
Step 1: Input value of num1 and num2
Step 2: If num1>num2: [num1 is larger]
Step 3: elif num1==num2: [Both numbers are equal]
Step 4: else: [Print num1 is smaller number]
Source Code:
num1=int(input("Enter First Number:"))
num2=int(input("Enter Second Number:"))
if(num1>num2):
print(num1,"is greater than",num2)
elif(num1==num2):
print(num1,"is equal to",num2)
else:
print(num1,"is smaller than",num2)
Output:
Run 1:

Run - 2:

Run - 3:

Result:
Thus, the program was executed successfully and the output was verified.
EX.NO.3 DISPLAY ADDED SUM OF TWO NUMBERS
Python program to input two numbers and add values.
Aim:-
To write a python program to input two numbers and add values
Algorithm:
Step 1: Input the value of num1and num2
Step 2: Add the two values
Step 3: Print the added values
Source code:-
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex.No : 4 DISPLAY LARGEST AND SMALLEST OF THREE NUMBERS


Write a Python program to find the biggest and smallest 3 numbers.
Aim:
To write a Python program to find the biggest and smallest among three numbers.
Algorithm:
Step 1: Input the value of num1, num2 and num3
Step 2: if (num1>num2 and num1>num3):
Step 3: elif (num3>num1and num3<num2):
Step 4: else: print the greater number among three numbers.
Source code:
num1=float(input("Enter the first value:"))
num2=float(input("Enter the second value:"))
num3=float(input("Enter the third value:"))
if (num1>num2 and num1>num3):
print(num1," is greater than both",num2,"and",num3)
elif (num2>num1 and num2>num3):
print (num2,"is greater than both",num1,"and",num3)
elif (num3 > num1 and num3 > num2):
print (num3,"is greater than both",num1,"and",num2)
else:
print ("Either any two values or all three values are equal")
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex.No : 5 GENERATE NESTED LOOP PATTERN-1


Write a Python program to generate the following pattern-1
*
**
***
****
*** **
Aim:
To write a Python program to generate left triangle star pattern using nested loop.

Algorithm:
Step 1: Input a value n.
Step 2: check condition for i in range (1, n+1)
Step 3: check condition for j in range (1, i+1)
Step 4: print * and use separator.
Step 5: print the output.
Source Code:
n=5
for i in range (1,n+1):
for j in range(1,i+1):
print ("*",end =" ")
print ( )
Output:

Result:
Thus,the program was executed successfully and the output was verified.

Ex.No :6 GENERATE NESTED LOOP PATTERN-II


Write a Python program to generate the following pattern
pattern-II
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Aim:
To write a Python program to display left triangle pattern using nested loop in python.
Algorithm:
Step 1: Input a value n.
Step 2: check condition for i in range (n+1):
Step 3: check condition for j in range (1, n-i+1)
Step 4: print j and use separator.
Step 5: print the output.
Source Code:-
n=5
for i in range(n+1):
for j in range (1,n-i+1):
print (j, end=" ")
print( )
Output:

Result:
Thus, the program was executed successfully and the output was verified.
Ex.No : 7 GENERATE NESTED LOOP PATTERN - III
Write a Python program to display the following pattern
Pattern - III
A
A B
A B C
A B C D
A B C D E
Aim:
To write a Python program to display left triangle alphabet pattern using nested loop.
Algorithm:
Step 1: Input a value n.
Step 2: check the condition for i in range (n)
Step 3: check the condition for j in range (i+1)
Step 4: print chr (j+65) and a separator
Step 5: print the output
Source Code:
n=5
for i in range (n):
for j in range (i+1):
print (chr(j+65),end=" ")
print( )
Output:

Result:
Thus, the program was executed successfully and the output was verified.
Ex.No : 8 SUM OF SERIES PATTERN -1 (1+ x+ x 2 + x 3 + x 4 … … x n ¿
Write a Python program to display sum of series:
Pattern- I
2 3 4 n
1+ x+ x + x + x … … x

Aim:
To write a Python program to input the value of x and n and print the sum of the
following series:1+ x+ x 2 + x 3 + x 4 … … x n
Algorithm:
Step 1: Input the value of x
Step 2: Input the value of n
Step 3: Initialize s=0 for calculating sum
Step 4: For a in range (n+1)
Step 5: s+=x**a to find sum of series
Step 6: print s
Source Code:
x= float (input ("Enter value of x :"))
n=int (input ("Enter the value of n :"))
s=0
for a in range(n+1):
s+=x**a
print ("sum of series", s)
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex.No: 9 SUM OF SERIES PATTERN-II (1−x+ x2− x3 + x 4 −… x n)


Write a Python program to display the sum of following series
Pattern-II
2 3 4 n
1−x+ x −x + x −… x

Aim:
To write a Python program to input the values of x and n and print the sum of series.
2 3 4 n
(1−x+ x − x + x −… x )

Algorithm:
Step 1: Input value of x
Step 2: Input value of n
Step 3: Initialize s=0 for calculating sum
Step 4: for a in range(n+1)
Step 5: If a%2==0
Step 6: s+=x**a
Step 7: else: b-=**a
Step 8: print sum of series
Source Code:
x= float (input("Enter the value of x:"))
n=int (input("Enter the value of n:"))
s=0
for a in range (n+1):
if a%2==0:
s+=x**a
else:
s-=x**a
print ("Sum of series:", s)
Output:

Result:
Thus, the program was executed successfully and the output was verified

Ex.No : 10 SUM OF SERIES PATTERN -III


2 3 4 n
x x x x
x− + − + …
2 3 4 n
Write a Python program to display sum of series.
Aim:
To write a Python program to input the value of x and n and print the sum of the
following series:
Algorithm:
Step 1: Input the value of x
Step 2: Input the value of n
Step 3: Initialize s=0
Step 4: For a in range (n+1):
Step 5: if a%2==0:
Step 6: s+=(x**2)/n fod add values are negative
Step 7: else: s-=(x**a)/n to print sum of series.
Step 8: print ("sum of series", s)
Source Code:
x= float (input ("Enter value of x :"))
n=int (input ("Enter the value of n :"))
s=0
for a in range(n+1):
if a%2==0:
s+=(x**a)/n
else:
s-=(x**a)/n
print ("Sum of series:", s)
Output:

Result:
Thus, the program was executed successfully and the output verified.

2 3 4 n
x x x x
Ex.No : 11 SUM OF SERIES PATTERN - IV ( x + − + … )
2 ! 3 ! 4 ! n!
2 3 4 n
x x x x
Write a Python program to print the sum of the following series x + − + …
2 ! 3 ! 4 ! n!

Aim:
To write a Python program to input the value of x, n and print the sum of the following
series.
Algorithm:
Step 1: Input the value of x
Step 2: Input the value of n
Step 3: Initialize s=x
Step 4: For a in range (i, n+1):
Step 5: fact= fact *a
Step 6: if a % 2==0
Step 7: s+=(x**a) / fact (to find sum of element)
Step 8: else: s-=(x**a) / fact (to find sum of element)
Step 9: print sum of series
Source Code:
x= int(input("Enter value of x:"))
n=int(input("Enter value of n:"))
sum=x
sign=1
for i in range(2,n+1):
fact=1
for j in range(1,i+1):
fact=fact*j
term=((x**i)*sign)/fact
sum=sum+term
sign=sign*-1 # or sign *=-1
print(sum)
print("Sum of first",n, "terms:",sum)
Output:
Result:
Thus, the program was executed successfully and the output was executed successfully
and the output was verified.

Ex.No : 12 PERFECT NUMBER OR NOT


Write a Python program to identify whether the number perfect or not
Aim:
To write a Python program to find whether the number is perfect number or not.
Algorithm:
Step 1: Take any number from user using input method
Step 2: Use for loop to iterate through number
Step 3: use if statement within for loop to add the proper division of the integer to the
sum variable.
Step 4: compare the original value with sum value.
Step 5: if they exactly matched then it is a perfect number, else it is not a perfect
number.
Source Code:
n= int(input("Enter any value to check it is perfect or not :"))
sum=0
for i in range (1,n):
if n % i==0:
sum += i
if sum==n:
print (n, "is a perfect number")
else:
print (n, "is not perfect number")
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex.No : 13 ARMSTRONG NUMBER


Write a Python program to find whether a number is an Armstrong number or not.
Aim:
To write a Python program to check whether the number is Armstrong number or not.
Algorithm:
Step 1: Take any number from user using input method
Step 2: Count the number of individual digits
Step 3: Divide the given number to individual digits
Step 4: Calculate the power of n for each individual and add those numbers
Step 5: Compare the original value with sum value
Step 6: if they exactly matched then it is an Armstrong number else it is not an Armstrong
number.
Source Code:
n=int(input("Enter any number to check whether it is a Armstrong number:"))
temp =n
total =0
while temp>0:
digit =temp%10
total =total +(digit **3)
temp =temp//10
if n==total:
print (n, "is an Armstrong number")
else:
print (n," is not an Armstrong number")
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex.No : 14 NUMBER PALINDROME


Write a Python program to check whether a number is palindrome or not.
Aim:
To write a Python program to check whether a number is palindrome or not.
Algorithm:
Step 1: Take any number from the user using input method
Step 2: Store the number in temporary variable say temp
Step 3: Count the number of individual digits
Step 4: Divide the given number into individual digits
Step 5: Calculate the reverse of numbers by adding remainder
Step 6: Compare the original number with reverse number
Step 7: If they exactly matched then it is a palindrome number else it is not palindrome
number
Source Code:
n=int (input ("Enter any number to check whether it is palindrome:"))
temp =n
rev =0
while n>0:
d =n%10
rev =rev*10+d
n =n//10
if temp == rev:
print (temp, "is a palindrome number")
else:
print (temp," is not an palindrome number")
Output:

Result:
Thus,the program was executed successfully and the output was verified.

Ex.No:15 PRIME OR COMPOSITE NUMBER


Write a Python program to check whether the given number is a prime or composite number.
Aim:
To write a Python program to check whether the given number is a prime or composite
number.
Algorithm:
Step 1: Take a number from user using input method
Step 2: Store the number in temporary variable say temp
Step 3: Use if-elif statement to check number is 0 or 1
Step 4: If the number 0 or 1 then give number is neither prime nor composite
Step 5: If user enter negative number ask user to enter positive number only
Step 6: User for loop to iterate through number
Step 7: Use if statement to check number is prime or composite
Step 8: If true print number is composite number otherwise prime number
Source Code:
n= int(input("Enter any number:"))
if (n==0 or n==1):
print (n, "number is neither prime nor composite"))
elif n>1:
for i in range (2,n):
if (n% i ==0):
print (n, " is not prime but composite number")
break
else:
print (n, " is prime but not composite")
else:
print(" please enter positive number only")
Output:

Result:
Thus, the program was executed successfully and the output was verified.
Ex.No:16 FIBONACCI SERIES
Write a Python program to display the terms of Fibonacci series.
Aim:
To write a Python program to display the terms of Fibonacci series.
Algorithm:
Step 1: Input integer asking how many terms to be printed
Step 2: Initialize a, b=0, 1
Step 3: s= a + b
Step 4: print (a, b, end=" ")
Step 5: for i in range (n-2):
Step 6: print (a+ b, end=" ")
Step 7: swap the values by a, b=b, a + b
Step 8: sum of digits, s=s + b
Step 9: print sum of terms of series

Source Code:
num = int(input(“Enter no of terms”))
n1, n2 = 0, 1
print(“Fibonacci Series: “, n1, n2)
for i in range(2, num):
n3 = n1 + n2
n1 = n2
n2 = n3
print(n3, end=" ")
print()
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex. No : 17 GCD AND LCM OF TWO INTEGERS


Write a Python program to compute GCD and LCM of two numbers.
Aim:
To write a Python program to compute the GCD and LCM of two integers.
Algorithm:
Step 1: Enter two positive integers n1 and n2.
Step 2: Declare two variables x and y and assigned values of n1, and n2 to them
Step 3: while [n2! =0] check the remainder of n1%n2 and n2 is equal to zero or not
Step 4: If true, n1 is calculated
Step 5: After that, value of n1 is assigned to GCD
Step 6: With the help of GCD calculate LCM of two integers
Step 7: print GCD and LCM
Source Code:
n1 = int(input("Enter First number :"))
n2 = int(input("Enter Second number :"))
x = n1
y = n2
while(n2!=0):
t = n2
n2 = n1 % n2
n1 = t
gcd = n1
print("GCD of {0} and {1} = {2}".format(x,y,gcd))
lcm = (x*y)/gcd
print("LCM of {0} and {1} = {2}".format(x,y,lcm))
Output:

Result:
Thus,the program was executed successfully and the output was verified.

Ex. No : 18 DISPLAY NUMBER OF VOWELS,CONSONANTS,UPPERCASE,LOWERCASE


Write a Python program to count and display the number of vowels, consonants, uppercase
and lowercase characters in a string.
Aim:
To write a Python program to count and display the number of vowels, consonants,
uppercase and lowercase characters in a string.
Algorithm:
Step 1: for loop is used to iterate each character in a string
Step 2: Inside for loop if statement is used to check whether the character is
a, e ,i ,o ,u , A,E,I,O,U
Step 3: If true, vowel is incremented otherwise consonant value is increased
Step 4: If character is in uppercase letter then uppercase is incremented by 1
Step 5: If statement to check whether character is uppercase or lowercase letter
Step 6: If character is a lowercase letter then lowercase is incremented by 1
Source Code:
s=input("Enter any string:")
vowel=consonant=uppercase=lowercase=0
for i in s:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):
vowel=vowel+1
else:
consonant=consonant+1
if i .isupper ( ):
uppercase=uppercase+1
if i .islower ( ):
lowercase=lowercase+1
print("Total number of vowel:",vowel)
print("Total number of consonant:",consonant)
print("Total number of uppercase letters:",uppercase)
print("Total number of lowercase letters:",lowercase)
Output:

Result:
Thus,the program was executed successfully and the output was verified.

Ex.No : 19 FIND NO OF VOWELS, CONSONANTS USING ASCII VALUES


Write a Python program, which uses ASCII values to find number of vowels to find number of
vowels and consonants.
Aim:
To write a Python program, this uses ASCII values to find number of vowels and consonants.
Algorithm:
Step 1: Use python inbuilt string function to find the number of uppercase and lowercase
letters
Step 2: Check whether string contains digits or alphabets.
Step 3: Use specified string containing digits and alphabets so that it shows mixed string
otherwise it counts total number of digits, uppercase and lowercase letters.
Source Code:
s=input("Enter Any String:")
vowels=consonants=uppercase=lowercase=digit=0
for i in s:
if i .isalnum():
if(ord(i)==65 or ord(i)==69 or ord(i)==73 or ord(i)==79
or ord(i)==85 or ord(i)==97 or ord(i)==101 or ord(i)==105 or ord(i)==111 or
ord(i)==117):
vowels=vowels+1
elif((ord(i)>=97 and ord(i)<=122) or (ord(i)>=65 and ord(i)<=90)):
consonants=consonants+1
if i .isupper():
uppercase+=1
elif i .islower():
lowercase+=1
elif i .isdigit():
digit+=1
else:
print("It is a mixed string")
print("Total number of vowels", vowels)
print("Total number of consonant", consonants)
print("Total number of uppercase letters", uppercase)
print("Total number of lowercase letters", lowercase)
print("Total number of digit", digit)
Output:

Result:
Thus,the program was executed successfully and the output was verified.

Ex. No : 20 PALINDROME,CONVERT CASE OF CHARACTERS


Write a python program to determine whether a string is a palindrome and convert the case
of characters.
Aim:
To write a Python program to input a string, and determine, whether it is a palindrome
or not.
Algorithm:
Step 1: Input a string
Step 2: swapcase( )function is used to change the case of characters of string
Step 3: Enter any string and reverse the position of characters
Step 4: check whether the reverse string is equal to the original string
Source code:
s=input("Enter Any String: ")
j=-1
flag=0
for i in s:
if i!=s[j]:
flag=1
break
j-=1
if flag==1:
print(s,"-->This String Is Not Palindrome")
else:
print(s,"-->This String Is Palindrome")
sc=s.swapcase()
print("String After Converting The Case Of Each Character: ",sc)
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex. No : 21 SMALLEST AND LARGEST NUMBER FROM LIST


Write a Python program to find the largest and smallest number in a list or tuple.
Aim:
To write a Python program to find the largest and smallest number in a list or tuple.
Algorithm:
Step 1: create an empty list.
Step 2: Input number of elements to put in list.
step 3: Iterating till num to append elements in list.
step4: min ( ) and max ( ) function are used to find large and smallest element in the list.
Source code:
listn=[ ]
num=int(input("Enter number of elements in list:"))
for i in range(1,num+1):
element=int(input("Enter elements:"))
listn.append(element)
print("Smallest element in list is:",min(listn))
print("Largest element in list is:",max(listn))
Output:

Result:
Thus, the program was executed successfully and the output was verified.

Ex. No: 22 INPUT A LIST AND SWAP ELEMENTS


Write a Python program to input a list of numbers and swap elements at the even location
with elements at odd location.
Aim:
To write a Python program to input a list of numbers and swap elements at the even
location with elements at odd location.
Algorithm:
Step 1: eval function evaluates the string like a python expression and returns the result
as an integer
Step 2: A list is directly added
Step 3: The length of list is calculated by len( ) function
Step 4: Then the conditional operator checks whether the total length is even or odd and
if it is odd then s variable contain the length of the list inputted is decreased by 1
Step 5: Then with the help of for loop the values are interchanged and we get desired
result.
Source Code:
val=eval(input("Enter A List:"))
print("Original List Is:",val)
s=len(val)
a=0
if s%2!=0:
a=a-1
for i in range(0,s,2):
val[i],val[i+1]=val[i+1],val[i]
print("List After Swapping:",val)
Output:
Run 1

Run 2

Result:
Thus, the program was executed successfully and the output was verified.

Ex. No : 23 INPUT A LIST, SEARCH AN ELEMENT IN LIST


Write a Python program to input list or tuple of elements, search for a given element in the
list or tuple.
Aim: To write a Python program to list or tuple of elements, search for a given element in the
list or tuple.

Algorithm:
Step 1: Create a empty list
Step 2: Enter five elements for the list
Step 3: Iterate till value to append element in the list
Step 4: If the element is in the list
Step 5: print element found at index and position
Source Code:
mylist=[]
print("Enter 5 elements for the list:")
for i in range(5):
value=int(input())
mylist.append(value)
print("Enter an element to be search:")
element=int(input())
for i in range(5):
if element==mylist[i]:
print("\n Element found at index:",i)
print("Element found at position",i+1)
Output:

Result:
Thus, the program was executed successfully and the output was verified.
Ex. No: 24 INPUT A LIST , FIND THE SMALLEST AND LARGEST NUMBER
Write a Python program to input a list of numbers and find the smallest and largest number
from the list.
Aim:
To write a Python program to input a list of numbers find the smallest and largest
number from the list.
Algorithm:
Step 1: Define find len(list)
Step 2: Find the length by using len( ) function
Step 3: Sort the values in the list
Step 4: Create list and call the function
Step 5: Print the largest and smallest element from the list
Source Code:
def find_len(list1):
length=len(list1)
list1.sort()
print("The largest element is:",list1[length-1])
print("The smallest element is:",list1[0])
print("The second largest element is:",list1[length-2])
print("The second smallest element is:",list1[1])
list1=[12,4,5,2,41,31,10,8,6,4]
largest=find_len(list1)
Output:

Result:
Thus, the program was executed successfully and the output was verified.
Ex. No : 25 CREATE DICTIONARY
Write a Python program, to create a dictionary with roll number, name and marks of n
students in a class.
Aim:
To write a Python program to create a dictionary with roll number, name and marks of n
students in a class and display the names of students who have scored above 75.
Algorithm:
Step 1: Enter number of students
Step 2: Create dictionary for result
Step 3: for i in range (no_of_std):
Step 4: Enter details of students
Step 5: Print result
Step 6: Display names of students who have got more than 75
Source Code:
no_of_std=int(input("Enter number of students:"))
result={}
for i in range(no_of_std):
print("Enter details of student number:",i+1)
roll_no=int(input("Roll no:"))
std_name=input("Student Name:")
marks=int(input("Marks:"))
result[roll_no]=[std_name,marks]
print(result)
for student in result:
if result[student][1]>75:
print("Student name who got more than 75 marks is/are",(result[student][0]))
Output:

Result:
Thus,the program was executed successfully and the output was verified.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy