Sum of Two Numbers: "Welcome"
Sum of Two Numbers: "Welcome"
Sum of Two Numbers: "Welcome"
In [97]:
print("welcome")
welcome
sum= 12
Area= 63
perimeter= 32
Average= 7.0
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 1/32
2/17/2020 2019111048
In [10]:
Answer= {10.0}
distance= 31.400000000000002
l=int(input("length:"))
b=int(input("breadth:"))
A=l*b*0.000247105
print("Area=",A,"acres")
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 2/32
2/17/2020 2019111048
In [33]:
Area= 314.0
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 3/32
2/17/2020 2019111048
In [32]:
Answer= 3125
Odd or Even
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 4/32
2/17/2020 2019111048
In [6]:
a is even
a is divisible by 7
Income tax
In [14]:
Print a message
In [15]:
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 5/32
2/17/2020 2019111048
In [32]:
print("\'Hi'")
print("'\'Hi'\'")
print("'\'\'Hi'\'\'")
'Hi'
''Hi''
'''Hi'''
Greeting message
In [36]:
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 6/32
2/17/2020 2019111048
In [37]:
Maran Mani
Assignment statement
In [81]:
width=17
height=12.0
delimiter='.'
a=width/2
b=width/2.0
c=height/3
d=1+2+5
e=delimiter*5
print("a=",a,",It is a float no")
print("b=",b,",It is a float no")
print("c=",c,",It is a float no")
print("d=",d,",It is a integer no ")
print("e=",e)
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 7/32
2/17/2020 2019111048
In [49]:
Volume= 523.3333333333334
Root= 2.8284271247461903
a=24.95
b=3
c=0.75
d=a*40/100
e=a-d
n=int(input("enter the number"))
g=n*e
f=b+(n-1)*c
A=f+g
print("Total wholesale cost=",A)
Distance= 2.8284271247461903
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 8/32
2/17/2020 2019111048
Sum= 2.68003675245
a= 8.22154
b= 0.02222222
Sum= 8
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 9/32
2/17/2020 2019111048
In [82]:
a= 4444
b= 66666
a=10
b=5
c=2
d=1
E=a+b+c+d
print("Total amount=",E)
Total amount= 18
Answer= Manimaran
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 10/32
2/17/2020 2019111048
In [88]:
Addition= Manimaran
Multiplication= ManiManiManiManiManiManiManiMani
X=250+130-70
Y=(32+5.2-3)*10
Z=100%(45/2)
A=(40+20)*30/10
B=((40+20)*30)/10
C=(40+20)*(30/10)
D=40+(20*30)/10
E=40+((20*30)/10)
F=40+(20*30/10)
print("X=",X)
print("Y=",Y)
print("Z=",Z)
print("A=",A)
print("B=",B)
print("C=",C)
print("D=",D)
print("E=",E)
print("F=",F)
X= 310
Y= 342.0
Z= 10.0
A= 180.0
B= 180.0
C= 180.0
D= 100.0
E= 100.0
F= 100.0
Fahrenheit to celsius
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 11/32
2/17/2020 2019111048
In [92]:
a=6.52
b=8*60+15
c=3*7*60+3*12
d=(b+c)/3600
e=d+a
print("Time of breakfast=",e,"AM")
GCD
In [44]:
a=int(input("enter no"))
b=int(input("enter no"))
if(a>b):
dividend=a
divisor=b
else:
dividend=b
divisor=a
while(divisor!=0):
rem=dividend%divisor
dividend=divisor
divisor=rem
print("GCD of",a,b,"is =",dividend)
GCD of 16 64 is = 16
Reassign values
In [107]:
a= 7
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 12/32
2/17/2020 2019111048
2ND EXERCISE
DECREMENT OF NUMBER
Divisible by 11
In [119]:
a is divisible by 11
In [126]:
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 14/32
2/17/2020 2019111048
In [136]:
Saturday
Vowel or not
In [139]:
It is a vowel
Root 1= 2.0
Root 2= 2.0
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 15/32
2/17/2020 2019111048
In [156]:
Very good
No of days in a month
In [157]:
Total day is 29
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 16/32
2/17/2020 2019111048
In [162]:
a=input("enter something")
b=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v'
,'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',
'S','T','U','V','W','X','Y','Z']
for i in b:
if(a==i):
m=i
if(a==m):
print("It is an alphabet")
elif(a==' '):
print("It is a blank space")
else:
print("It is a number")
It is an alphabet
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 17/32
2/17/2020 2019111048
In [164]:
n=50
m=70
for i in range(n,m+1):
print(i)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
n=75
m=15
for i in range(n,m-5,-5):
print(i)
75
70
65
60
55
50
45
40
35
30
25
20
15
In [18]:
Average= 2.5
n=1
m=100
sum=0
for i in range(n,m+1):
if(i%2!=0):
sum=sum+i
print("Odd sum=",sum)
square= 55
cube= 225
Armstrong or not
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 19/32
2/17/2020 2019111048
In [33]:
Palindrome or not
In [39]:
1
2
3
4
5
6
7
8
9
11
22
33
44
55
66
77
88
99
101
No of digits in a number
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 20/32
2/17/2020 2019111048
In [41]:
-21
10
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 21/32
2/17/2020 2019111048
sum= -7.666666666666666
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 22/32
2/17/2020 2019111048
In [67]:
import math
for i in range(0,375,15):
x=(i*math.pi)/180
print(math.sin(x))
print(math.cos(x))
print(math.tan(x))
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 23/32
2/17/2020 2019111048
0.0
1.0
0.0
0.25881904510252074
0.9659258262890683
0.2679491924311227
0.49999999999999994
0.8660254037844387
0.5773502691896257
0.7071067811865475
0.7071067811865476
0.9999999999999999
0.8660254037844386
0.5000000000000001
1.7320508075688767
0.9659258262890683
0.25881904510252074
3.7320508075688776
1.0
6.123233995736766e-17
1.633123935319537e+16
0.9659258262890683
-0.25881904510252085
-3.7320508075688763
0.8660254037844387
-0.4999999999999998
-1.7320508075688783
0.7071067811865476
-0.7071067811865475
-1.0000000000000002
0.49999999999999994
-0.8660254037844387
-0.5773502691896257
0.258819045102521
-0.9659258262890682
-0.267949192431123
1.2246467991473532e-16
-1.0
-1.2246467991473532e-16
-0.25881904510252035
-0.9659258262890684
0.26794919243112225
-0.5000000000000001
-0.8660254037844386
0.577350269189626
-0.7071067811865475
-0.7071067811865477
0.9999999999999997
-0.8660254037844384
-0.5000000000000004
1.7320508075688754
-0.9659258262890683
-0.25881904510252063
3.732050807568879
-1.0
-1.8369701987210297e-16
5443746451065123.0
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 24/32
2/17/2020 2019111048
-0.9659258262890682
0.25881904510252113
-3.7320508075688714
-0.8660254037844386
0.5000000000000001
-1.732050807568877
-0.7071067811865477
0.7071067811865474
-1.0000000000000004
-0.5000000000000004
0.8660254037844384
-0.5773502691896265
-0.2588190451025207
0.9659258262890683
-0.26794919243112264
-2.4492935982947064e-16
1.0
-2.4492935982947064e-16
EXCERCISE 3
Student details
In [68]:
student=['Manimaran.M','Mech','Anna university','Guindy','Chennai']
print(student)
A=['a','b','c','d','e','f','g','h','i','j']
print("First three letters=",A[0:4])
print("Three letters in middle=",A[4:7])
print("Index no 2 to end=",A[2:])
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 25/32
2/17/2020 2019111048
In [3]:
numlist=[1,2,3,4,5,6,7,8,9,10]
print("List is:",numlist)
numlist[5]=100
print("List after updation is:",numlist)
numlist.append(200)
print("List after appending a value is:",numlist)
del numlist[3]
print("List after deleting a value is:",numlist)
A=[1,2,3,4,5,6,7,8,9,10]
del A[2:4]
print(A)
[1, 2, 5, 6, 7, 8, 9, 10]
list1=[1,'a',"abc",[2,3,4,5],8.9]
i=0
while i <(len(list1)):
print("list1[",i,"]=",list1[i])
i+=1
list1[ 0 ]= 1
list1[ 1 ]= a
list1[ 2 ]= abc
list1[ 3 ]= [2, 3, 4, 5]
list1[ 4 ]= 8.9
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 26/32
2/17/2020 2019111048
In [10]:
A=[1,9,11,13,15]
print("original list:",A)
A[2]=[3,4,7]
print("After inserting another list, the updated list is:",A)
A=[1,2,3,4,5]
B=A
print("A=",A)
print("B=",B)
C=A[2:6]
print("C=",C)
A= [1, 2, 3, 4, 5]
B= [1, 2, 3, 4, 5]
C= [3, 4, 5]
A=['p','r','o','g','r','a','m']
A[2:5]=[]
print(A)
A=[1,2,3,4,5,6,7,8,9,10]
sum=0
for i in A:
sum+=i
print("sum=",sum)
avg=sum/float(len(A))
print("Avg=",avg)
sum= 55
Avg= 5.5
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 27/32
2/17/2020 2019111048
In [21]:
A=[4,1,8,2,9,3,0]
print("Largest value in the list is:",max(A))
A=[1,2,3,4,5]
for i in range(len(A)):
print("Index=",i)
Index= 0
Index= 1
Index= 2
Index= 3
Index= 4
A=[1,2,3,4,5,6,7,6,5,4]
print("Original list=",A)
i=0
while i<len(A):
num=A[i]
for j in range(i+1,len(A)):
val=A[j]
if val ==num:
A.pop(j)
i+=1
print("List after removing duplicates=",A)
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 28/32
2/17/2020 2019111048
In [27]:
import functools
def add(x,y):
return x+y
A=[1,2,3,4,5,6,7,8,9,10]
print("Sum of values in list=",functools.reduce(add,A))
def check(x):
if(x%2==0):
return 1
A=list(filter(check,range(1,11)))
print("Even numbers=",A)
def mul_2(x):
x*=2
return x
A=[1,2,3,4,4,5]
print("Original list=",A)
A1=list(map(mul_2,A))
print("Modified list=",A1)
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 29/32
2/17/2020 2019111048
In [1]:
A=['x','y','z']
print("List A=",A)
B=tuple(A)
print("Tuple A=",B)
C=('x','y','z')
print("Tuple C=",C)
D=list(C)
print("List C=",D)
(v1,v2,v3)=(1,2,3)
print(v1,v2,v3)
T1=(100,200,300)
(v1,v2,v3)=T1
print(v1,v2,v3)
(v1,v2,v3)=(2+4,5/3+4,9%6)
print(v1,v2,v3)
A=[1,2,3]
B=tuple(A)
print(B)
1 2 3
100 200 300
6 5.666666666666667 3
(1, 2, 3)
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 30/32
2/17/2020 2019111048
In [4]:
Details=(('Manimaran.M','Mech'),('Prasanth.R','Mech'),('Nandha','Mech'),('Sabari','Mech'),
('Harisankar','Mech'))
for i in Details:
print(i)
('Manimaran.M', 'Mech')
('Prasanth.R', 'Mech')
('Nandha', 'Mech')
('Sabari', 'Mech')
('Harisankar', 'Mech')
A=(1,2,3,4,5,6,7,8,9,10)
print("4th element=",A[3])
print("4th element form the last=",A[-4])
4th element= 4
4th element form the last= 7
v1=10
v2=20
print("v1=",v1,"v2=",v2)
(v1,v2)=(v2,v1)
print("v1=",v1,"v2=",v2)
v1= 10 v2= 20
v1= 20 v2= 10
In [9]:
b= ('mani', 'gmail.com')
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 31/32
2/17/2020 2019111048
In [10]:
A=[1,-2,-3,-4,5,6,7,8,10]
newtup=()
for i in A:
if(i>0):
newtup+=(i,)
print("New tuple=",newtup)
A=(1,2,3,4,5,6,7,8,9,10)
print("Length=",len(A))
Length= 10
Tup=("Mani",89,82,4)
print("%s got %d marks in CSA and his aggregate was %.2f"%(Tup[0],Tup[1],Tup[2]))
To reverse a tuple
In [13]:
A=(1,2,3,4,5,6,7,8,9,10)
b=list(A)
b.reverse()
c=tuple(b)
print("The reversed tuple is=",c)
In [ ]:
https://jlab.annauniv.edu:8000/user/be2019111048/lab/workspaces/auto-8 32/32