Python
Python
Python
Date:4.7.2023
Aim:
Program:
ans=n1+n2
Output:
the result is 30
Result:
Date:6.7.2023
Program:
fact=1
for x in range(1,n+1):
fact=fact*x
print(fact)
Output:
720
Result:
Date:4.7.2023
Program:
temp=n
r=0
while(n>0):
dig=n%10
r=(r*10)+dig
n=n//10
print(r)
Output:
Result:
Date:4.7.2023
Program:
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:
Output:
349
Result:
Date:4.7.2023
Program:
c=0
for i in range (2,n):
if (n%i)==0:
c=1
if(c==0):
else:
Output:
97 is prime number
Result:
Date:4.7.2023
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:
Output:
5432
Result:
Date:4.7.2023
7.Sum of digits:
Program:
sum=0
while (num>0):
r=num%10
sum=sum+r
num=num//10
Output:
Result:
Date:4.7.2023
8.Odd or even:
Program:
n=int(input("Enter n value:"))
i=1
while(i<=n):
if (i%2!=0):
else:
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:
Date:4.7.2023
Program:
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:
Result:
Date:4.7.2023
Program:
def factorial(n):
if n==0:
return 1
else:
return n*factorial (n-1)
print (factorial(n))
Output:
24
Result:
Date:4.7.2023
Program:
for val in s:
continue
print(val)
Output:
d
h
Result:
Date:4.7.2023
Program:
c=1
while(c>0):
print("Menu")
print("****")
print("2.Convert Uppercase")
print("3.Convert Lowercase")
print("4.Count occurence")
ch=int(input("Enter Any Choice"))
if(ch==1):
print(str.capitalize(s))
elif(ch==2):
print(str.upper(s))
elif(ch==3):
print(str.lower(s))
else:
print(str.count(s,ss))
Output:
>>>
Menu
****
2.Convert Uppercase
3.Convert Lowercase
4.Count occurence
DHANUSIYA
Result:
Thus the program will be successfully executed.
Date:4.7.2023
Program:
myarray=array('i',[])
myarray.insert(i,v)
m=0
for i in range(len(myarray)):
if m< myarray[i]:
m=myarray[i]
Output:
The largest is 90
Result:
Date:4.7.2023
Program:
c=1
while (c>0):
print("menu")
print("******")
print("1.creation of array")
print("2.append")
print("3.insert")
print("4.pop")
print("5.remove")
print("6.display")
myarray=array('i',[])
for i in range(0,n):
myarray.insert(i,v)
for i in myarray:
print(i)
elif(ch==2):
myarray.append(v)
elif(ch==3):
myarray.insert(i,v)
elif(ch==4):
myarray.pop(i)
elif(ch==5):
myarray.remove(v)
elif(ch==6):
for i in myarray:
print(i)
menu
******
1.creation of array
2.append
3.insert
4.pop
5.remove
6.display
35
67
89
90
24
26
Date:4.7.2023
Program:
print("list")
c=1
while(c>0):
print("menu")
print("----")
print("1.creation of list")
print("2.length")
print("3.search")
print("5.sorting")
if(ch==1):
list_A=[]
for i in range(n):
ele=int(input())
list_A.append(ele)
if(ch==2):
if(ch==3):
if sv in list_A:
print(sv,"is present")
else:
if(ch==4):
if(ch==5):
Output:
list
menu
----
1.creation of list
2.length
3.search
5.sorting
100
50
30
36
menu
----
1.creation of list
2.length
3.search
5.sorting
Minimum value is 30
Result:
Thus the program will be successfully executed.
Date:4.7.2023
16.List of sum:
Program:
list_A=[]
for i in range(n):
ele=int(input())
list_A.append(ele)
Output:
20
30
10
SUM= 60
Result:
Thus the program will be successfully executed.
Date:4.7.2023
17.List of sorting:
Program:
list_A=[]
for i in range(n):
ele=input()
list_A.append(ele)
Output:
33
90
24
Result:
Date:4.7.2023
Program:
t1=('p','y','t','h','o','n','p','r','o','g','r','a','m')
print(t1)
Output:
('p', 'y', 't', 'h', 'o', 'n', 'p', 'r', 'o', 'g', 'r', 'a', 'm')
Result:
19.Creation of dictionary:
Program:
i=0;
dict1={}
while(i<n):
dict1[str1]=rollno
i=i+1
print(dict1)
Output:
Date:4.7.2023
Program:
{'id':'1','name':'Alice'}
print(employees)
Output:
Date:4.7.2023
Program:
common_password=['abcd','asdfg']
while True:
print('you Entered{password}')
break
else:
continue
print(password)
Output:
dhanusiya
Result:
Date:4.7.2023
Program:
def student(name,age,year='1',course='BCA',college='Noble'):
print('Student Details:',name,age,year,course,college)
for i in range(n):
student(name,age)
student(name,age,"II","CS","SBK")
Output:
Result:
Date:4.7.2023
Program:
def add_num(*args):
sum=0
print("The sum of values are")
for i in range:
sum +=i
print(sum)
print("Menu")
print("****")
if(ch==1):
add_num(a,b)
if(ch==2):
add_num(a,b,c)
if(ch==3):
add_num(a,b,c,d)
Output:
Menu
****
60
Result:
Date:4.7.2023
Program:
c=0
w=0
l=0
f1=open(filename,'w')
f1.close()
f2=open(filename,'r')
data=f2.readlines()
print(data)
for i in data:
c=c+len(i)
w=w+len(i.split())
l=l+1
f2.close()
Output:
Result:
Thus the program will be successfully executed.
Date:4.7.2023
Program:
rec={}
i=1
while(i<=n):
rec[name]=marks
i=i+1
for x in rec:
print("\t",x,"\t",rec[x])
Output:
priya 99
divya 99
jeyanthi 99
dhanusiya 99
Result:
Date:4.7.2023
Program:
d={}
for x in word:
d[x]=d.get(x,0)+1
for k,v in d.items():
print(k,"occured",v,"times")
Output:
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:
Date:4.7.2023
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:
Date:4.7.2023
Program:
s=lambda n:n*n
print("The square of 4 is=",s(4))
Output:
Result:
Date:4.7.2023
Program:
Output:
Result:
Date:4.7.2023
30.Module program:
Program:
def print_table(ourNum):
for x in range(1,11):
result=ourNum*x
print(ourNum,"*",x,"=",result)
import mul
mul.print_table(ourNum)
Output:
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:
Date:4.7.2023
Program:
import sys
print("Number of arguments:",len(sys.argv))
num=int(sys.argv[1])
if (num%2)==0:
else:
Output:
C:\Users\Computer 38>D:
D:\ cd Dhanu.0129
D:\Dhanu.0129>py commandlineprogram.py 45
Number of arguments: 2
Result: