0% found this document useful (0 votes)
13 views27 pages

Harri Es

Uploaded by

ragegopalelm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views27 pages

Harri Es

Uploaded by

ragegopalelm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

SERIAL PROGRAM PAGE SIGNATURE

NO NO
1 To input a welcome message and 3
display it
2 To input two numbers and display the 4
largest/smaller number
3 To input three numbers and display the 4-5
largest/smaller number

4 To generate the following patterns using 5-6


nested loop
5 To generate the following pattern using 6-7
nested loop
6 To generate the following pattern using 7
nested loop
7 To write a program to input the value of 7
x and n and print the sum of the
following series
8 To write a program to input the value of 8
x and n and print the sum of the
following series
9 To write a program to input the value of 9
x and n and print the sum of the
following series
10 To write a program to input the value of 9-10
x and n and print the sum of the
following series
11 To determine whether a number is a 10
perfect no
12 To determine whether a number is a 10-
Armstrong number 11
13 To determine whether a number is a 11-
plaindrome number 12
14 To input a number and check if the 12
number is a prime or composite number
1
15 To display the terms of a Fibonacci 12-
series 13
16 To compute the greatest common 13
divisor
17 To compute the least common divisor 14
18 To count and display the number of 14-
vowels,consonants,uppercase,lowercase 15
characters in string

19 To input a string and determine whether 15-


it is a palindrome or not 16
20 To convert the case of character in string 16
21 To find largest/smallest number in list 16
22 To find largest/smallest number in tuple 16-
17
23 To input a list of numbers and swap 17
elements at even location with the
elements at the odd location
24 To input a list of element , search for a 17-
given elements in the list 18
25 To input a list of element , search for a 18
given elements in the tuple
26 To create a dictionary with roll number, 18-
name and marks of n students in a class 19
and display the name of students who
have mark above 75
27 To find absolute value 19-
20
28 To sort 3 numbers 20-
21
29 To find divisibility of a number 21-
22
30 To find factorial of a positive number 22
31 To find mean numeric values stored in 22
the list
2
32 To find linear search on list of numbers 22-
23
33 To find frequency of elements in the list 23
34 To find mean numeric values stored in 24
the tuple
35 To find linear search on tuple of 24
numbers
36 To find frequency of elements in the 24-
tuple 25
37 To count the number of times a 25
character appears in a given string using
dictionary
38 To create a dictionary with names of 26
employees their salary and access them

1.
Aim: To input a welcome message and display it
Program:
a=input("enter a wlecome message:")
print(a)
output:
enter a wlecome message:hello
hello
2.
Aim: To input two numbers and display the largest/smaller number
Program:
a=int(input("enter a number:"))

3
b=int(input("enter a number:"))
if a>b:
print(a,"is greater")
print(b,"is smaller")
else:
print(a,"is smaller")
print(b,"is greater")
output:
enter a number:3
enter a number:5
3 is smaller
5 is greater
3.
Aim: To input three numbers and display the largest/smaller number
Program:
a=int(input("enter a number:"))
b=int(input("enter a number:"))
c=int(input("enter a number:"))
if a>b and a>c:
print(a,"is greater")
if b<c:
print(b,"is smaller")
else:
print(c,"is smaller")

4
elif b>a and b>c:
print(b,"is greater")
if a<c:
print(a,"is smaller")
else:
print(c,"is smaller")
elif c>a and c>b:
print(c,"is greater")
if a<b:
print(a,"is smaller")
else:
print(b,"is smaller")
output:
enter a number:5
enter a number:6
enter a number:4
6 is greater
4 is smaller
4.
Aim: To generate the following patterns using nested loop
Program:
for i in range(1,7):
for j in range(1,i):
print("*",end='')

5
print()
output:
*
**
***
****
*****
5.
Aim: To generate the following pattern using nested loop
Program:
for i in range(7,1,-1):
for j in range(1,i):
print(j,end='')
print()
output:
123456
12345
1234
123
12
1
6.
Aim: To generate the following pattern using nested loop
Program:

6
for i in range(1,7):
a=65
for j in range(1,i):
print(chr(a),end='')
a=a+1
print()
output:
A
AB
ABC
ABCD
ABCDE
7.
Aim: To write a program to input the value of x and n and print the
sum of the following series
Program:
sum=1
x=int(input("enter a number"))
n=int(input("enter a number"))
for i in range(1,n+1):
sum=sum+x**i
print(sum)
output:
enter a number2

7
enter a number5
63
8.
Aim: To write a program to input the value of x and n and print the
sum of the following series
Program:
sum=1
x=int(input("enter a number"))
n=int(input("enter a number"))
for i in range(1,n+1):
y=x**i
if i%2!=0:
y=y*-1
sum=sum+y
print(sum)
output:
enter a number2
enter a number5
-21
9.
Aim: To write a program to input the value of x and n and print the
sum of the following series
Program:
x=int(input("enter a number:"))

8
n=int(input("enter a number:"))
sum=0
for i in range(2,n+1):
y=x**i/i
sum=sum+y
print(sum)
output:
enter a number:5
enter a number:9
280447.3115079365

10.
Aim: To write a program to input the value of x and n and print the
sum of the following series
Program:
import math
x=int(input("enter a number:"))
n=int(input("enter a number:"))
sum=0
for i in range(2,n+1):
y=x**i/math.factorial(i)
sum=sum+y
print(sum)

9
output:
enter a number:2
enter a number:5
6.266666666666667

11.
Aim: To determine whether a number is a perfect number
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(n,"is perfect number")
output:
enter a number6
6 is perfect number
12.
Aim: To determine whether a number is an armstrong number
Program:
n=int(input("enter a 3 digit number:"))
sum=0
x=sum

10
while(x>0):
y=x%10
sum=y**3
x//=10
if(n==sum):
print(n,"is armstrong number")
else:
print(n,"is not armstrong number")
output:
enter a 3 digit number:412
412 is not armstrong number
13.
Aim: To determine whether a number is a palindrome
Program:
n=int(input("enter a number:"))
x=str(n)
y=x[::-1]
if x==y:
print(n,"is palindrome")
else:
print(n,"is not palindrome")
output:
enter a number:12321
12321 is palindrome

11
14.
Aim: To input a number and check if the number is a prime or
composite number
Program:
n=int(input("enter a number"))
for i in range(2,n):
if n%i==0:
print("composite")
break
else:
print("prime")
output:
enter a number3
prime
15.
Aim: To display the terms of a Fibonacci series
Program:
n=int(input("enter a number"))
x=0
y=1
print(x)
print(y)
for i in range(n-2):
z=x+y

12
print(z)
x=y
y=z
output:
enter a number4
0
1
1
2
16.
Aim: To compute the greatest common divisor
Program:
import math
n1=int(input("enter a number"))
n2=int(input("enter a number"))
print(math.gcd(n1,n2))
output:
enter a number2
enter a number6
2
17.
Aim: To compute the least common divisor
Program:
import math

13
n1=int(input("enter a number"))
n2=int(input("enter a number"))
print((n1*n2)//math.gcd(n1,n2))
output:
enter a number6
enter a number8
24
18.
Aim: To count and display the number of
vowels,consonants,uppercase,lowercase characters in string
Program:
s=input("enter a string")
u=0
l=0
v=0
c=0
for i in s:
if i.isupper():
u+=1
if i.islower():
l+=1
if i in "aeiouAEIOU":
v+=1
elif i.isalpha():

14
c+=1
print("no of upper case:",u)
print("no of lower case:",l)
print("no of vowels:",v)
print("no of consonant:",c)
output:
enter a stringHArrIEs
no of upper case: 4
no of lower case: 3
no of vowels: 3
no of consonant: 4
19.
Aim: To input a string and determine whether it is a palindrome or
not
Program:
s=input("enter a string")
if s==s[::-1]:
print(s,"is palindrome")
else:
print(s,"is not palindrome")
output:
enter a string:dad
dad is palindrome
20.

15
Aim: To convert the case of character in string
Program:
s=input("enter a string :")
print(s.swapcase())
output:
enter a string :JAsim
jaSIM
21.
Aim: To find largest/smallest number in list
Program:
n=eval(input("enter a list of numbers"))
print("maximum",max(n))
print("minimum",min(n))
output:
enter a list of numbers[20,24,35,69,58]
maximum 69
minimum 20
22.
Aim: To find largest/smallest number in tuple
Program:
n=eval(input("enter a tuple of number"))
print("maximum",max(n))
print("minimum",min(n))
output:

16
enter a tuple of number(65,25,48,14)
maximum 65
minimum 14
23.
Aim: To input a list of numbers and swap elements at even location
with the elements at the odd location
Program:
l=eval(input("enter a list of numbers"))
for i in range(0,len(l)-1,2):
l[i],l[i+1]=l[i+1],l[i]
print(l)
output:
enter a list of numbers[25,14,35,65]
[14, 25, 65, 35]
24.
Aim: To input a list of element , search for a given elements in the list
Program:
l=eval(input("enter a list of numbers:"))
x=int(input("enter the number to be found:"))
y=l.index(x)
print(x,"is at the index",y)
output:
enter a list of numbers:[25,14,35,65]
enter the number to be found:14

17
14 is at the index 1
25.
Aim: To input a tuple of element , search for a given elements in the
tuple
Program:
l=eval(input("enter a tuple of numbers:"))
x=int(input("enter the number to be found:"))
y=l.index(x)
print(x,"is at the index",y)
output:
enter a tuple of numbers:(25,45,35,65,85)
enter the number to be found:35
35 is at the index 2
26.
Aim: To create a dictionary with roll number, name and marks of n
students in a class and display the name of students who have mark
above 75
Program:
n=int(input("enter a number:"))
d={}
for i in range(n):
roll=int(input("enter the roll number:"))
name=input("enter the name:")
mark=int(input("enter the mark of student:"))
d[roll]=[name,mark]
18
print(d)
for i in d:
if d[i][1]>75:
print(d[i][0])
output:
enter a number:3
enter the roll number:1
enter the name:midhun
enter the mark of student:72
enter the roll number:2
enter the name:jasim
enter the mark of student:80
enter the roll number:3
enter the name:dhivakar
enter the mark of student:88
{1: ['midhun', 72], 2: ['jasim', 80], 3: ['dhivakar', 88]}
jasim
Dhivakar
27.
Aim:To find absolute value
Program:
x=int(input("enter a number:"))
if x<0:
print(x*-1)

19
else:
print(x)
output:
enter a number:5
5
28.
Aim:To sort 3 numbers
Program:
x=int(input("enter a number:"))
y=int(input("enter a number:"))
z=int(input("enter a number:"))
if x<y and x<z:
print(x,end=" ")
if y<z:
print(y,z,sep=" ")
else:
print(z,y,sep=" ")
elif y<x and y<z:
print(y,end=" ")
if x<z:
print(x,z,sep=" ")
else:
print(z,x,sep=" ")
elif z<x and z<y:

20
print(z,end=" ")
if x<y:
print(x,y,sep=" ")
else:
print(y,x,sep=" ")
else:
print("all values are equal")
output:
enter a number:25
enter a number:65
enter a number:35
25 35 65
29.
Aim: To find divisibility of a number
Program:
x=int(input("Enter a number:"))
if x%10==0:
print(x,"is divisible of 10")
else:
print(x,"is not divisible of 10")
output:
Enter a number:25
25 is not divisible of 10
30.

21
Aim: to find the factorial of a positive number
Program:
x=int(input("enter a number:"))
n=1
for i in range(1,x+1):
n=n*i
print(n)
output:
enter a number:6
720
31.
Aim: To find mean numeric values stored in the list
Program:
l=[20,30,50,47,12]
print(sum(l)/len(l)
ouput:
31.8
32.
Aim: To find linear search on list of numbers
Program:
l=[20,58,2,14,57]
x=int(input("enter the number to be found:"))
for i in l:
if x==i:

22
print(x,"is in the index of",l.index(x))
break
else:
print(x,"is not in the list")
output:
enter the number to be found:57
57 is in the index of 4
33.
Aim: To find frequency of elements in the list
Program:
l=[4,2,4,6,8,2,1,4]
x=int(input("enter the number:"))
c=0
for i in l:
if x==i:
c=c+1
print(x,"appears",c,"in the list")
ouput:
enter the number:4
4 appears 3 in the list
34.
Aim:To find mean of values stored in the tuple
Program:
x=(20,45,35,85,65)

23
print(sum(x)/len(x))
output:
50.0
35.
Aim: To find linear search on a tuple of numbers
Program:
x=(20,45,68,95,58)
n=int(input("enter the number to be found:"))
for i in x:
if n==i:
print(n,"is in the index",x.index(n))
break
else:
print(n,"is not in the tuple")
output:
enter the number to be found:95
95 is in the index 3
36.
Aim: To count the frequency of element in a tuple
Program:
x=(25,47,65,65,25,47,65)
c=0
n=int(input("enter a number:"))
for i in x:

24
if n==i:
c=c+1
print(n,"appears",c,"in the tuple")
output:
enter a number:25
25 appears 2 in the tuple
37.
Aim: to count the number of times a character appears in a given
string using dictionary
Program:
s="hari ram"
d={}
for i in s:
if i not in d:
d[i]=1
else:
d[i]=d[i]+1
print(d)
output:
{'h': 1, 'a': 2, 'r': 2, 'i': 1, ' ': 1, 'm': 1}
38.
Aim: To create a dictionary with names of employees their salary and
access them
Program:

25
d={}
x=int(input("enter a number:"))
for i in range(x):
name=input("enter the name:")
salary=int(input("enter the salary:"))
d[name]=salary
print(d)
output:
enter a number:3
enter the name:a
enter the salary:159
enter the name:b
enter the salary:357
enter the name:c
enter the salary:258
{'a': 159, 'b': 357, 'c': 258}

26
27

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