Ex.
no: 1 Addition of two numbers
Date:4.7.2023
Aim:
To write a python program to add two numbers
Program:
n1=int(input("enter the value :"))
n2=int(input("enter the value :"))
ans=n1+n2
print("the result is",ans)
Output:
enter the value10
enter the value20
the result is 30
Result:
Thus the program will be successfully executed.
[Link]: 2 Factorial of numbers
Date:6.7.2023
Program:
n=int(input("enter the value of n"))
fact=1
for x in range(1,n+1):
fact=fact*x
print(fact)
Output:
enter the value of n6
720
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] number using while loop:
Program:
n=int(input(" Enter the number:"))
temp=n
r=0
while(n>0):
dig=n%10
r=(r*10)+dig
n=n//10
print(r)
Output:
Enter the number:45678
87654
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] number checking:
Program:
n=int(input(" Enter the number:"))
temp=n
r=0
while(n>0):
dig=n%10
r=r+dig*dig*dig
n=n//10
print(r)
if (r==temp):
print(temp,"is Armstrong")
else:
print (temp,"is not a Armstrong")
Output:
Enter the number:256
349
256 is not a Armstrong
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] number checking:
Program:
n=int(input("Enter the number"))
c=0
for i in range (2,n):
if (n%i)==0:
c=1
if(c==0):
print (n,"is prime number")
else:
print (n,"is not a prime number")
Output:
Enter the number97
97 is prime number
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] number checking
Program:
n=int(input(" Enter the number:"))
temp=n
r=0
while(n>0):
dig=n%10
r=(r*10)+dig
n=n//10
print(r)
if (r==temp):
print(temp,"is pallindrome")
else:
print (temp,"is not a pallindrome")
Output:
Enter the number:2345
5432
2345 is not a palindrome
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] of digits:
Program:
num=int(input("Enter the number:"))
sum=0
while (num>0):
r=num%10
sum=sum+r
num=num//10
print ("the sum of digit is",sum)
Output:
Enter the number:2901
the sum of digit is 12
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] or even:
Program:
n=int(input("Enter n value:"))
i=1
while(i<=n):
if (i%2!=0):
print(i,"is odd number")
else:
print(i,"is even number")
i+=1
Output:
Enter n value:21
1 is odd number
2 is even number
3 is odd number
4 is even number
5 is odd number
6 is even number
7 is odd number
8 is even number
9 is odd number
10 is even number
11 is odd number
12 is even number
13 is odd number
14 is even number
15 is odd number
16 is even number
17 is odd number
18 is even number
19 is odd number
20 is even number
21 is odd number
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] number within the limit:
Program:
lower=int(input("Enter the lower limit"))
upper=int(input("Enter the upper limit"))
for i in range(lower,upper+1):
if i>1:
for j in range(2,i):
if (i%j)==0:
break
else:
print(i)
break
Output:
Enter the lower limit3
Enter the upper limit10
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] using recursion:
Program:
def factorial(n):
if n==0:
return 1
else:
return n*factorial (n-1)
n=int(input ("Enter the number:"))
print (factorial(n))
Output:
Enter the number:4
24
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] constant in string:
Program:
s= str(input("Enter the name:"))
for val in s:
if val=="a" or val== "e" or val=="i" or val=="o" or val=="u":
continue
print(val)
Output:
Enter the name:dhanu ammu
d
h
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] in free defined function:
Program:
c=1
while(c>0):
s=input("Enter Any String")
print("Menu")
print("****")
print("[Link] First Letter")
print("[Link] Uppercase")
print("[Link] Lowercase")
print("[Link] occurence")
ch=int(input("Enter Any Choice"))
if(ch==1):
print([Link](s))
elif(ch==2):
print([Link](s))
elif(ch==3):
print([Link](s))
else:
ss=input("Enter Any search character")
print([Link](s,ss))
c=int(input("Do you want to Continue(1-0)"))
Output:
>>>
Enter Any Stringdhanusiya
Menu
****
[Link] First Letter
[Link] Uppercase
[Link] Lowercase
[Link] occurence
Enter Any Choice2
DHANUSIYA
Do you want to Continue(1-0)0
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] largest number in an array:
Program:
from array import*
myarray=array('i',[])
n=int(input("Enter the number of elements"))
for i in range (0,n):
v=int(input("Enter the number "))
[Link](i,v)
print("The given element are")
m=0
for i in range(len(myarray)):
if m< myarray[i]:
m=myarray[i]
print("The largest is",m)
Output:
Enter the number of elements2
Enter the number 20
Enter the number 90
The given element are
The largest is 90
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] free defined method:
Program:
from array import*
c=1
while (c>0):
print("menu")
print("******")
print("[Link] of array")
print("[Link]")
print("[Link]")
print("[Link]")
print("[Link]")
print("[Link]")
ch=int(input("enter the value"))
if(ch==1):
myarray=array('i',[])
n=int(input("enter the number of elements"))
for i in range(0,n):
v=int(input("enter the members"))
[Link](i,v)
for i in myarray:
print(i)
elif(ch==2):
v=int(input("enter the number"))
[Link](v)
elif(ch==3):
v=int(input("enter the number"))
i=int(input("enter the place to insert values"))
[Link](i,v)
elif(ch==4):
v=int(input("enter the index of remove valu"))
[Link](i)
elif(ch==5):
v=int(input("enter the element to remove"))
[Link](v)
elif(ch==6):
for i in myarray:
print(i)
c=int(input("do you want to continue(y-1/n-0)"))
Output:
menu
******
[Link] of array
[Link]
[Link]
[Link]
[Link]
[Link]
enter the value1
enter the number of elements6
enter the members35
enter the members67
enter the members89
enter the members90
enter the members24
enter the members26
35
67
89
90
24
26
do you want to continue(y-1/n-0)0
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] program for pre-defined function:
Program:
print("list")
c=1
while(c>0):
print("menu")
print("----")
print("[Link] of list")
print("[Link]")
print("[Link]")
print("[Link] and min")
print("[Link]")
ch=int(input("Enter your choice"))
if(ch==1):
list_A=[]
n=int(input("enter the number of elements"))
for i in range(n):
ele=int(input())
list_A.append(ele)
if(ch==2):
print("Length of list is",len(list_A))
if(ch==3):
sv=int(input("Enter the number to search"))
if sv in list_A:
print(sv,"is present")
else:
print(sv,"is not present")
if(ch==4):
print("Maximum value is ",max(list_A))
print("Minimum value is",min (list_A))
if(ch==5):
print("Sorting value is ",sorted(list_A))
c=int (input("DO YOU WANT TO CONTINUE(y-1/n-0)"))
Output:
list
menu
----
[Link] of list
[Link]
[Link]
[Link] and min
[Link]
Enter your choice1
enter the number of elements4
100
50
30
36
DO YOU WANT TO CONTINUE(y-1/n-0)1
menu
----
[Link] of list
[Link]
[Link]
[Link] and min
[Link]
Enter your choice4
Maximum value is 100
Minimum value is 30
DO YOU WANT TO CONTINUE(y-1/n-0)
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] of sum:
Program:
list_A=[]
n=int(input("Enter the number of elements"))
for i in range(n):
ele=int(input())
list_A.append(ele)
print("SUM=" the result is,(list_A))
Output:
Enter the number of elements3
20
30
10
SUM= 60
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] of sorting:
Program:
list_A=[]
n=int(input("Enter the number of elements"))
for i in range(n):
ele=input()
list_A.append(ele)
print("sorting value is",sorted (list_A))
Output:
Enter the number of elements3
33
90
24
sorting value is ['24', '33', '90']
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] the occurence of value(using tuple):
Program:
t1=('p','y','t','h','o','n','p','r','o','g','r','a','m')
print(t1)
t2=str(input("Enter the element to check its occurence"))
print(t2,"is present in",[Link](t2),"times in the place of",[Link](t2))
Output:
('p', 'y', 't', 'h', 'o', 'n', 'p', 'r', 'o', 'g', 'r', 'a', 'm')
Enter the element to check its occurencer
r is present in 2 times in the place of 7
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] of dictionary:
Program:
n=int(input("Enter the value"))
i=0;
dict1={}
while(i<n):
str1=input("Enter the name")
rollno=int(input("Enter the Rollno"))
dict1[str1]=rollno
i=i+1
print('Entered dictionary elements are')
print(dict1)
Output:
Enter the value2
Enter the namedhanusiya
Enter the Rollno1001
Enter the nameniraimathi
Enter the Rollno1002
Entered dictionary elements are
{'dhanusiya': 1001, 'niraimathi': 1002}
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] of dictionary using key and value:
Program:
employees=dict(input('Enter key and value separated by space:').split()for i in range(2))
{'id':'1','name':'Alice'}
print(employees)
Output:
Enter key and value separated by space:10 dhanusiya
Enter key and value separated by space:20 niraimathi
{'10': 'dhanusiya', '20': 'niraimathi'}
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] the password using dictionary:
Program:
common_password=['abcd','asdfg']
while True:
password=input('Enter your password:')
if (len(password)>5and password not in common_password):
print('you Entered{password}')
break
else:
print('pick a strong password')
continue
print(password)
Output:
Enter your password:sld
pick a strong password
Enter your password:dhanusiya
you Entered{password}
dhanusiya
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] details using defauld func:
Program:
def student(name,age,year='1',course='BCA',college='Noble'):
print('Student Details:',name,age,year,course,college)
n=int(input("Enter the number of students"))
for i in range(n):
name=input("Enter student name")
age=int(input("Enter student age"))
student(name,age)
student(name,age,"II","CS","SBK")
Output:
Enter the number of students2
Enter student namedhanusiya
Enter student age19
Student Details: dhanusiya 19 1 BCA Noble
Enter student nameniraimathi
Enter student age13
Student Details: niraimathi 13 1 BCA Noble
Student Details: niraimathi 13 II CS SBK
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] using variable length argument:
Program:
def add_num(*args):
sum=0
print("The sum of values are")
for i in range:
sum +=i
print(sum)
print("Menu")
print("****")
print("[Link] of two numbers:")
print("[Link] of three numbers:")
print("[Link] of four numbers:")
ch=int(input("Enter your choice"))
if(ch==1):
a=int(input("Enter the first number"))
b=int(input("Enter the second number"))
add_num(a,b)
if(ch==2):
a=int(input("Enter the first number"))
b=int(input("Enter the second number"))
c=int(input("Enter the third number"))
add_num(a,b,c)
if(ch==3):
a=int(input("Enter the first number"))
b=int(input("Enter the second number"))
c=int(input("Enter the third number"))
d=int(input("Enter the fourth number"))
add_num(a,b,c,d)
Output:
Menu
****
[Link] of two numbers:
[Link] of three numbers:
[Link] of four numbers:
Enter your choice2
Enter the first number10
Enter the second number20
Enter the third number30
The sum of values are
60
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] character ,word and line in a file:
Program:
filename=input("Enter a file name:")
c=0
w=0
l=0
f1=open(filename,'w')
[Link]('computer science engineering\n')
[Link]('electronics and communication engineering\n')
[Link]()
f2=open(filename,'r')
data=[Link]()
print(data)
for i in data:
c=c+len(i)
w=w+len([Link]())
l=l+1
[Link]()
print('The number of characters are:',c)
print('The number of words are:',w)
print('The number of lines are:',l)
Output:
Enter a file name:details
['computer science engineering\n', 'electronics and communication engineering\n']
The number of characters are: 71
The number of words are: 7
The number of lines are: 2
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] student name and percentage using dictionary:
Program:
rec={}
i=1
n=int(input("Enter number of students:"))
while(i<=n):
name=input("Enter student name:")
marks=input("Enter % of marks of student:")
rec[name]=marks
i=i+1
print("names of student","\t","% of marks")
for x in rec:
print("\t",x,"\t",rec[x])
Output:
Enter number of students:4
Enter student name:dhanusiya
Enter % of marks of student:99
Enter student name:divya
Enter % of marks of student:99
Enter student name:jeyanthi
Enter % of marks of student:99
Enter student name:priya
Enter % of marks of student:99
names of student % of marks
priya 99
divya 99
jeyanthi 99
dhanusiya 99
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] occurrence of letter using dictionary:
Program:
word=input("Enter any word:")
d={}
for x in word:
d[x]=[Link](x,0)+1
for k,v in [Link]():
print(k,"occured",v,"times")
Output:
Enter any word:colourfullflowers
c occured 1 times
e occured 1 times
f occured 2 times
l occured 4 times
o occured 3 times
s occured 1 times
r occured 2 times
u occured 2 times
w occured 1 times
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] operation using positional argument(return more than
one value)
Program:
def calc(a,b):
sum=a+b
sub=a-b
mul=a*b
div=a/b
return sum,sub,mul,div
t=calc(100,50)
for x in t:
print(x)
Output:
150
50
5000
2.0
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] of number using lambda function:
Program:
s=lambda n:n*n
print("The square of 4 is=",s(4))
print("The square of 5 is=",s(5))
Output:
The square of 4 is= 16
The square of 5 is= 25
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] among w number using lambda function:
Program:
s=lambda a,b:a if a>b else b
print("The biggest of 10,20 is:",s(10,20))
print("The biggest of 100,200 is :",s(100,200))
Output:
The biggest of 10,20 is: 20
The biggest of 100,200 is : 200
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] program:
Program:
def print_table(ourNum):
for x in range(1,11):
result=ourNum*x
print(ourNum,"*",x,"=",result)
import mul
ourNum=int(input("Enter the table Number"))
mul.print_table(ourNum)
Output:
Enter the table Number12
12 * 1 = 12
12 * 2 = 24
12 * 3 = 36
12 * 4 = 48
12 * 5 = 60
12 * 6 = 72
12 * 7 = 84
12 * 8 = 96
12 * 9 = 108
12 * 10 = 120
Result:
Thus the program will be successfully executed.
[Link]: 1 Addition of two numbers
Date:4.7.2023
[Link] line program:
Program:
import sys
print("Number of arguments:",len([Link]))
num=int([Link][1])
if (num%2)==0:
print("The number is even")
else:
print("The provided number is odd")
Output:
C:\Users\Computer 38>D:
D:\ cd Dhanu.0129
D:\Dhanu.0129>py [Link] 45
Number of arguments: 2
The provided number is odd
Result:
Thus the program will be successfully executed.