Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

PROGRAM:1

AIM:
To input a welcome message and display it.
PROGRAM:
x=input("Enter a welcome message:")
print(x)
OUTPUT:
Enter a welcome message:Hello
Hello

PROGRAM:2
AIM:
To input two numbers and display the smallest/largest
number.
PROGRAM:
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
if x<y:
print(x,"is smaller")
print(y,”is greater")
else:
print(y,"is smaller")
print(x,"is greater")

1
OUTPUT:
Enter the first number:54
Enter the second number:45
45 is smaller
54 is greater

PROGRAM:3
AIM:
To input three numbers and display the smallest/largest
number.
PROGRAM:
x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
z=int(input("Enter the third number:"))
if x<y and x<z:
print(x,"is smaller")
if y>z:
print(y,"is greater")
else:
print(z,"is greater")
elif y<x and y<z:
print(y,"is smallest")
if x>z:
print(x,"is greater")

2
else:
print(z,"is greater")
elif z<x and z<y:
print(z,"is smaller")
if x>y:
print(x,"is greater")
else:
print(y,"is greater")F
OUTPUT:
Enter the first number:56
Enter the second number:25
Enter the third number:44
25 is smallest
56 is greater

PROGRAM:4
AIM:
To develop a program to display the following pattern:
*
**
***
****
*****
PROGRAM:

3
for i in range(1,7):
for j in range(1,i):
print("*",end='')
print()
OUTPUT:
*
**
***
****
*****
PROGRAM:5
To develop a program to display the following pattern:
12345
1234
123
12
1
PROGRAM:
for i in range(6,1,-1):
for j in range(1,i):
print(j,end=' ')
print()
OUTPUT:
12345

4
1234
123
12
1

PROGRAM:6
To develop a program to display the following pattern:
A
AB
ABC
ABCD
ABCDE
PROGRAM:
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

5
ABCD
ABCDE

PROGRAM:7
To find the sum of the series:
1+x+x2+x3+x4+……….+xn
PROGRAM:
sum=1
x=int(input("Enter the value of x:"))
n=int(input("Enter the value of n:"))
for i in range(1,n+1):
sum=sum+x**i
print(sum)
OUTPUT:
Enter the value of x:12
Enter the value of n:5
6

PROGRAM:8
To find the sum of the series:
1-x+x2-x3+x4-………xn
PROGRAM:
sum=1
x=int(input("Enter the value of x:"))

6
n=int(input("Enter the value of n:"))
for i in range(1,n+1):
y=x**i
if i%2!=0:
y=y*-1
sum=sum+y
print(sum)
OUTPUT:
Enter the value of x:2
Enter the value of n:5
-31

PROGRAM:9
To find the sum of the series:
x+x2/2-x3/3+x4/4-…….xn/n
PROGRAM:
sum=1
x=int(input("Enter the value of x:"))
n=int(input("Enter the value of n:"))
for i in range(1,n+1):
y=x**i/i
if i%2!=0:
y=y*-1
sum=sum+y

7
print(sum)
OUTPUT:
Enter the value of x:2
Enter the value of n:3
-1.6666666666666665

PROGRAM:10
To find the sum of the series:
x+x2/2!-x3/3!+x4/4!-……xn/n!
PROGRAM:
sum=1
x=int(input("Enter the value of x:"))
n=int(input("Enter the value of n:"))
for i in range(1,n+1):
y=x**i
f=1
for j in range (1,i+1):
f=f*j
y=y/f
if i%2!=0:
y=y*-1
sum=sum+y
print(sum)
OUTPUT:

8
Enter the value of x:2
Enter the value of n:3
-0.33333333333333326

PROGRAM:11
AIM:
To determine whether a number is perfect number.
PROGRAM:
sum=0
n=int(input("Enter a number:"))
for i in range(1,n):
if n%i==0:
sum=sum+i
if sum==n:
print("Perfect Number")
else:
print("Not Perfect")
OUTPUT:
Enter a number:6
Perfect Number

PROGRAM:12
AIM:
To determine whether a number is Armstrong number.

9
PROGRAM:
n=int(input("Enter a number:"))
temp=n
sum=0
while temp!=0:
x=temp%10
sum=sum+x**3
temp=temp//10
if n==sum:
print(n,"is armstrong number")
else:
print(n,"is not a armstrong number")
OUTPUT:
Enter a number:407
407 is armstrong number

PROGRAM:13
AIM:
To determine whether a number is palindrome or not.
PROGRAM:
n=int(input("Enter a number:"))
for i in range(2,n):
if n%i==0:
print(n,"is not prime number")

10
break
else:
print(n,"is prime number")
OUTPUT:
Enter a number:5
5 is prime number

PROGRAM: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(n,"is composite number")
break
else:
print(n,"is prime number")
OUTPUT:
Enter a number:8
8 is composite number

PROGRAM:15

11
AIM:
To display the terms of Fibonacci series.
PROGRAM:
n=int(input("Enter a number:"))
x=0
y=1
print(x)
print(y)
for i in range(0,n-2):
z=x+y
print(z)
x=y
y=z
OUTPUT:
Enter a number:10
0
1
1
2
3
5
8
13
21

12
34

PROGRAM:16
AIM:
To compute greater common divisor of two integers.
PROGRAM:
x=int(input("Enter the value of x:"))
y=int(input("Enter the value of y:"))
import math
s=math.gcd(x,y)
print(s,"is the GCD")
OUTPUT:
Enter the value of x:12
Enter the value of y:6
6 is the GCD

PROGRAM:17
AIM:
To compute least common multiple of two integers.
PROGRAM:
x=int(input("Enter the value of x:"))
y=int(input("Enter the value of y:"))
import math
s=math.gcd(x,y)

13
print(x*y//s,"is the LCM")
OUTPUT:
Enter the value of x:12
Enter the value of y:6
12 is the LCM

PROGRAM:18
AIM:
To count and display the number of vowels, consonants,
uppercase, lowercase characters in a string.
PROGRAM:
v=0
c=0
u=0
l=0
n=eval(input("Enter a string:"))
for i in n:
if i.isupper():
u+=1
if i.islower():
l+=1
if i in "aeiouAEIOU":
v+=1
elif i.isalpha():

14
c+=1
print("There are",v,"vowels")
print("There are",c,"consonants")
print("There are",u,"upper case")
print("There are",l,"lower case")
OUTPUT:
Enter a string:"SWaTAIOAe"
There are 6 vowels
There are 3 consonants
There are 7 upper case
There are 2 lower case

PROGRAM:19
AIM:
To input a string and determine whether it is palindrome or
not.
PROGRAM:
n=eval(input("Enter a string:"))
s=n[::-1]
if s==n:
print("It is palindrom")
else:
print("It is not palindrom")
OUTPUT:

15
Enter a string:"Naruto Uzumaki"
It is not palindrom

PROGRAM:20
AIM:
To convert the case of characters in a string.
PROGRAM:
s=eval(input("Enter a string:"))
print(s.swapcase())
OUTPUT:
Enter a string:"I am a student"
i AM A STUDENT

PROGRAM:21
AIM:
To find the smallest\largest number in a list of numbers.
PROGRAM:
s=eval(input("Enter a list of numbers:"))
print("Maximum value is",max(s))
print("Minimum value is",min(s))
OUTPUT:
Enter a list of numbers:[2,6,25,10,1]
Maximum value is 25
Minimum value is 1

16
PROGRAM:22
AIM:
To find the smallest\largest number in a Tuple of numbers.
PROGRAM:
Enter a tuple of numbers:(23,44,3,1,99)
Maximum value is 99
Minimum value is 1
OUTPUT:
Enter a tuple of numbers:(23,44,3,1,99)
Maximum value is 99
Minimum value is 1

PROGRAM:23
AIM:
To input a list of numbers and swap elements at the 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:[1,2,3,4,5]

17
[2, 1, 4, 3, 5]

PROGRAM:24
AIM:
To input a list of elements, search for a given element in the
list.
PROGRAM:
l=eval(input("Enter a list of numbers:"))
x=int(input("Number to be searched:"))
print(l.index(x))
OUTPUT:
Enter a list of numbers:[12,43,23,55,33]
Number to be searched:33
4

PROGRAM:25
AIM:
To input a tuple of elements, search for a given element in the
tuple.
PROGRAM:
l=eval(input("Enter a tuple of numbers:"))
x=int(input("Number to be searched:"))
print(l.index(x))
OUTPUT:

18
Enter a tuple of numbers:(1,4,6,4,90)
Number to be searched:90
4

PROGRAM:26
AIM:
To create a dictionary with the roll number, name and mark of
n students in a class and display the names of students who have
marks above 75.
PROGRAM:
n=int(input("Enter the number of students:"))
d={}
for i in range(n):
Name=input("Enter the name:")
Roll=int(input("Enter the roll number:"))
Mark=int(input("Enter the mark:"))
d[Roll]=[Name,Mark]
print(d)
for i in d:
if d[i][1]>75:
print (d[i][0])
OUTPUT:
Enter the number of students:5
Enter the name: Akash

19
Enter the roll number:01
Enter the mark:69
Enter the name: Aswin
Enter the roll number:02
Enter the mark:70
Enter the name: Sanjay
Enter the roll number:03
Enter the mark:89
Enter the name: Anbuthamizh
Enter the roll number:04
Enter the mark:78
Enter the name: Madesh
Enter the roll number:05
Enter the mark:99
{1: ['Akash', 69], 2: ['Aswin', 70], 3: ['Sanjay', 89], 4: ['Anbuthamizh',
78], 5: ['Madesh', 99]}
Sanjay
Anbuthamizh
Madesh

PROGRAM:27
AIM:
To input a number and find the absolute value.
PROGRAM:

20
x=int(input("Enter a number:"))
if x<0:
print(x*-1)
else:
print(x)
OUTPUT:
Enter a number: -88
88

PROGRAM:28
AIM:
To input three number and sort three 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 x<y and y<z:
print(x, end=" ")

21
if x<z:
print(x,z,sep=" ")
else:
print(z,x,sep=" ")
elif z<x and z<y:
print(z, end=" ")
if y<x:
print(y,x,sep=" ")
else:
print(x,y,sep=" ")

else:
print("Numbers are equal")
OUTPUT:
Enter a number:1
Enter a number:2
Enter a number:3
123

PROGRAM:29
AIM:
To input a number and find the divisibility of the number.
PROGRAM:
x=int(input("Enter a number:"))

22
if x%10==0:
print("The number is divisible by 10")
else:
print("The number is not divisible by 10")
OUTPUT:
Enter a number:100
The number is divisible by 10

PROGRAM:30
AIM:
To input a number and finding the factorial of a positive
number.
PROGRAM:
x=int(input("Enter a number:"))
fact=1
for i in range(1,x+1):
fact=fact*i
print(fact)
OUTPUT:
Enter a number:12
479001600

PROGRAM:31
AIM:

23
To input a list and counting the frequency of elements in a list.
PROGRAM:
L=eval(input("Enter a set of numbers:"))
x=int(input("enter the number for which we need the frequency:"))
c=0
for i in L:
if x==i:
c+=1
print(x," appears",c," times" )
OUTPUT:
Enter a set of numbers:[8,5,3,7,15,8,2,4,8]
enter the number for which we need the frequency:8
8 appears 3 times

PROGRAM:31
AIM:
To input a list and finding the minimum, maximum, mean of
values stored in a tuple.
PROGRAM:
L=eval(input("Enter a list of numbers:"))
print("Maximum:",max(L))
print("Minimum:",min(L))
print("Mean:",sum(L)/len(L))
OUTPUT:

24
Enter a list of numbers:[2,5,2,5,4,6,8,9,4]
Maximum: 9
Minimum: 2
Mean: 5.0

PROGRAM:32
AIM:
To input a tuple and counting the frequency of elements in a
tuple.
L=eval(input("Enter a tuple of numbers:"))
x=int(input("enter the number for which we need the frequency:"))
c=0
for i in L:
if x==i:
c+=1
print(x," appears",c," times" )
OUTPUT:
Enter a tuple of numbers:(8,2,6,4,8,1,8,7)
enter the number for which we need the frequency:8
8 appears 3 times

PROGRAM:33
AIM:

25
To count the number of times a character appears in a given
string using a dictionary.
s="MINATO NAMIKAZE"
D={}
for i in s:
if i not in D:
D[i]=1
else:
D[i]=D[i]+1
print(D)
OUTPUT:
{'M': 2, 'I': 2, 'N': 2, 'A': 4, 'T': 1, 'O': 1, ' ': 1, 'K': 1, 'Z': 1}

PROGRAM:34
AIM:
To create a dictionary with names of employees, their salary
and access them.
PROGRAM:
D={}
n=int(input("Enter the number of Employees:"))
for i in range(n):
name=input("Enter the name:")
salary=int(input("Enter the salary:"))
D[name]=salary

26
OUTPUT:
Enter the number of Employees:2
Enter the name:SANJAY
Enter the salary:10000
Enter the name:ANBU
Enter the salary:10000000

27
28

You might also like