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

CLASS 11 RECORD PROGRAMS

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

CLASS 11 RECORD PROGRAMS

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

Class 11 2024-2025 Python lab programs

Program-1
Aim: Input a welcome message and display it
Source code:
a=input("enter a message:")
print(a)

output:
enter a message: welcome you all to the party
welcome you all to the party

Result:
The program has been executed successfully.
Program-2
Aim: Input two numbers and display the larger/smaller
number
Source code:
n1=int(input("enter a number:"))
n2=int(input("enter a number:"))
if n1>n2:
largest=n1
else:
largest=n2
print("The largest number is:",largest)

Output:
enter a number:9
enter a number:4
The largest number is: 9

Result:
The program has been executed successful
Program-3
Aim: Input three numbers and display the largest/smallest
number
Source Code:
n1=int(input("enter a number:"))
n2=int(input("enter a number:"))
n3=int(input("enter a number:"))
if n1>n2 and n1>n3:
largest=n1
elif n2>n1 and n2>n3:
largest=n2
else:
largest=n3
print("The largest number is:",largest)
Output:
enter a number:6
enter a number:9
enter a number:3
The largest number is: 9
Result:The program has been executed successfull
Program-4A
Aim: Generate the following pattern using nested loop
Pattern-1:
*
**
***
****
*****
Source Code:
for i in range(1,7):
for j in range(1,i):
print("*",end='')
print()
Output:
*
**
***
****
*****
Result:
The program has been executed successfully.
Program-4B
Aim: Generate the following pattern using nested loop
Pattern-2:
12345
1234
123
12
1
Source Code:
n=0
s=5
for i in range(s,0,-1):
for j in range(1,n+1):
print(end="")
for j in range(1,i+1):
print(j,end="")
n+=2
print()
Output:
12345
1234
123
12
1
Result: The program has been executed successfully.
Program-4C
Aim: Generate the following pattern using nested loop
Pattern-3:
A
AB
ABC
ABCD
ABCDE

Source Code:
for i in range(65,70):
for j in range(65,i+1):
print(chr(j),end="")
j=j+1
print()

Output:
A
AB
ABC
ABCD
ABCDE

Result: The program has been executed successfully.


Program-5
Aim: Write a program to input the value of x and n
and print the sum of the following series:
5A)Series is: 1+x+x2+x3+x4+….+xn
Source Code:
x=float(input("enter value of x:"))
n=int(input("enter value for n:"))
s=0
for a in range(n+1):
s+=x**a
print("sum of first",n,"terms:",s)
Output:
enter value of x:12.8
enter value for n:2
sum of first 2 terms: 177.64000000000004

Result: The program has been executed successfully.


5B)Series is: 1-x+x2-x3+x4-…xn
Source Code:
x=float(input("enter value of x:"))
n=int(input("enter value for n:"))
s=0
sign=+1
for a in range(n+1):
term=(x**a)*sign
s+=term
sign*=-1
print("sum of first",n,"terms:",s)

Output:
enter value of x:28
enter value for n:4
sum of first 4 terms: 593461.0

Result: The program has been executed successfully.


5C)Series is: x+x2/2+x3/3+x4/4+….xn/n
Source Code:
x=int(input("enter value of x:"))
n=int(input("enter value for n:"))
s=x
sign=+1
for a in range(2,n+1):
f=1
for i in range(1,a+1):
f=i
term=((x**a)*sign)/f
s+=term
sign*=-1
print("sum of first",n,"terms:",s)
Output:
enter value of x:2
enter value for n:4
sum of first 4 terms: 5.333333333333334

Result: The program has been executed successfully.


5D)Series is: x+x2/2!+x3/3!+x4/4!+….xn/n!
Source Code:
x=int(input("enter value of x:"))
n=int(input("enter value for n:"))
s=x
sign=+1
for a in range(2,n+1):
f=1
for i in range(1,a+1):
f*=i
term=((x**a)*sign)/f
s+=term
sign*=-1
print("sum of first",n,"terms:",s)
Output:
enter value of x:8
enter value for n:4
sum of first 4 terms: 125.33333333333333

Result: The program has been executed successfully


Program-6
Aim: Determine whether a number is
6A) a perfect number
Source Code:
n=int(input("enter the number:"))
sum=0
for i in range(1,n):
if n%i==0:
sum=sum+i
if sum==n:
print("The number ",n,"is a perfect number")
else:
print("The number ",n,"is not a perfect number")

Output:
enter the number:8128
The number 8128 is a perfect number

Result: The program has been executed successfully.


6B) Armstrong number
Source Code:
num=int(input("enter a 3-digit number:"))
sum=0
temp=num
while temp>0:
digit=temp%10
sum+=digit**3
temp//=10
if num==sum:
print(num,"is an armstrong number")
else:
print(num,"is not an armstrong number")

Output:
enter a 3-digit number:123
123 is not an armstrong number

Result: The program has been executed successfully.


6C) Palindrome number
Source Code:
num=int(input("enter number:"))
wnum=num
rev=0
while wnum>0:
digit=wnum%10
rev=rev*10+digit
wnum=wnum//10
if num==rev:
print("The number ",num,"is a palindrome")
else:
print("The number ",num,"is not a palindrome")

Output:
enter number:565
The number 565 is a palindrome

Result: The program has been executed successfully.


Program-7
Aim: Input a number and check if the number is a
prime or composite number
Source Code:
num=int(input("enter any number:"))
if num>1:
for i in range(2,num):
if num%i==0:
print(num,"is a composite number")
break
else:
print(num,"is a prime number")
elif num==0 or 1:
print(num,"is neither prime nor composite number")
else:
print()

Output:
enter any number:3
3 is a prime number

Result: The program has been executed successfully.


Program-8
Aim: Display the terms of a Fibonacci series
Source Code:
t=int(input("how many terms?"))
first=0
second=1
print("\nfibonacci series is:")
print(first,",",second,end=",")
for i in range(2,t):
next=first+second
print(next,end=",")
first=second
second=next

Output:
how many terms?5
fibonacci series is:
0 , 1,1,2,3,

Result: The program has been executed successfully.


Program-9
Aim: Compute the greatest common divisor and least
common multiple of two integers

Source Code:
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 H.C.F of ",x,"and",y,"is",hcf)
print("The L.C.M of ",x,"and",y,"is",lcm)

Output:
enter first number:12
enter second number:90
The H.C.F of 12 and 90 is 6
The L.C.M of 12 and 90 is 180.0

Result: The program has been executed successfully


Program-10
Aim: Count and Display the number of vowels,
consonants, uppercase, lowercase characters in string
Source Code:
string=input("enter your string:")
vowels=consonants=uppercase=lowercase=0
vowels_list=['a','e','i','o','u','A','E','I','O','U']
for i in string:
if i in vowels_list:
vowels+=1
if i not in vowels_list:
consonants+=1
if i.isupper():
uppercase+=1
if i.islower():
lowercase+=1
print("Number of vowels in this string=",vowels)
print("Number of consonants in this string=",consonants)
print("Number of uppercase characters in this
string=",uppercase)
print("Number of lowercase characters in this
string=",lowercase)
Output:
enter your string: My name is Revathi
Number of vowels in this string= 6
Number of consonants in this string= 12
Number of uppercase characters in this string= 2
Number of lowercase characters in this string= 13

Result: The program has been executed successfully.


Program-11
Aim: Input a string and determine whether it is a
palindrome or not

Source Code:
string=input("enter a string:")
length=len(string)
mid=int(length/2)
rev=-1
for a in range(mid):
if string[a]==string[rev]:
a+=1
rev-=1
else:
print(string,"is not a palindrome")
break
else:
print(string,"is a palindrome")

Output:
enter a string: malayalam
malayalam is a palindrome

Result: The program has been executed successfully.


Program-12
Aim: Find the largest/smallest number in a list/tuple
Source Code:
val=eval(input("enter a tuple:"))
print("The tuple is:",val)
mx=max(val)
mn=min(val)
print("maximum number in the tuple:",mx)
print("minimum number in the tuple:",mn)

Output:
enter a tuple:(2,1,8,4,5,7)
The tuple is: (2, 1, 8, 4, 5, 7)
maximum number in the tuple: 8
minimum number in the tuple: 1

Result: The program has been executed successfully.


Program-13
Aim: Input a list of numbers and swap elements at the
even location with the elements at the odd location

Source Code:
val=eval(input("enter a list:"))
print("original list is:",val)
s=len(val)
if s%2!=0:
s=s-1
for i in range(0,s,2):
print(i,i+1)
val[i],val[i+1]=val[i+2],val[i]
print("List after swapping:",val)
Output:
enter a list:[3,1,4,2,9,7,5]
original list is: [3, 1, 4, 2, 9, 7, 5]
01
23
45
List after swapping: [4, 3, 9, 4, 5, 9, 5]

Result: The program has been executed successfully.


Program-14
Aim: Input a list/tuple of elements search for a given
element in the list/tuple
Source Code:
lst=eval(input("enter list:"))
length=len(lst)
element=int(input("enter element to be searched for:"))
for i in range(0,length):
if element==lst[i]:
print(element,"found of index",i)
break
else:
print(element,"not found in given list")

Output:
enter list:[16,15,2,8,5,6,19,20,45]
enter element to be searched for:18
18 not found in given list

Result: The program has been executed successfully.


Program-15
Aim: Input a list of numbers and find the smallest and
largest number from the list

Source Code:
lst=eval(input("enter list:"))
a=min(lst)
b=max(lst)
print("The smallest number in the given list:",a)
print("The largest number in the given list:",b)
Output:
enter list:[9,1,7,2,5,3]
The smallest number in the given list: 1
The largest number in the given list: 9

Result: The program has been executed successfully.


Program-16
Aim: Create a dictionary with the roll number, name
and marks of ‘n’ students in a class and display the
names of students who have marks above 75.
Source Code:
n=int(input("How many students?"))
stu={}
for i in range(1,n+1):
print("enter details of student",(i))
rollno=int(input("Rollnumber:"))
name=input("Name:")
marks=float(input("Marks:"))
d={"Rollno":rollno, "Name":name,"Marks":marks}
key="stu"+str(i)
stu[key]=d
print("students with marks>75 are:")
for i in range(1,n+1):
key="stu"+str(i)
if stu[key]["Marks"]>=75:
print(stu[key]
Output:
How many students?2
enter details of student 1
Rollnumber:11
Name:Revathi
Marks:75
enter details of student 2
Rollnumber:1
Name:Rajani
Marks:82
students with marks>75 are:
{'Rollno': 11, 'Name': 'Revathi', 'Marks': 75.0}
{'Rollno': 1, 'Name': 'Rajani', 'Marks': 82.0}

Result: The program has been executed successfully.

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