Assignment
Assignment
Write a function calculation() such that it can accept two variables and
calculate the addition and subtraction of them. And also it must return both
addition and subtraction in a single return call
CODE:
def calculation(a,b):
c = int(a)+int(b)
d = int(a)-int(b)
return (c,d)
OUTPUT:
(50, 30)
CODE:
def showEmployee(nm,sl):
if len(sl)==0 :
print('name and salary : ',nm,9000)
else:
print('name and salary : ',nm,sl)
showEmployee(name,salary)
OUTPUT CASE 1:
OUTPUT CASE 2:
# Driver code
x=2
y=3
swap(x, y)
print(x)
print(y)
OUTPUT :
2
3
4. Write python function code - Area calculator
CODE:
def rectanglearea(a,b):
x = int(a)*int(b)
return (x)
def trianglearea(c,d):
y = (1/2)*int(c)*int(d)
return (y)
def squarearea(e):
z = int(e)*int(e)
return (z)
if choice == '1':
n1 = input("enter length : ")
n2 = input("enter breath : ")
f1 = rectanglearea(n1, n2)
print('rectangle area : ',f1)
if choice == '2':
n3 = input("enter height : ")
n4 = input("enter base : ")
f2 = trianglearea(n3,n4)
print('triangle area : ',f2)
if choice == '3':
n5 = input("enter side : ")
f3 = squarearea(n5)
print('square area : ',f3)
OUTPUT CASE 1 :
enter length : 20
enter breath : 30
OUTPUT CASE 2:
enter height : 50
enter base : 20
OUTPUT CASE 3:
CODE:
def stringpaline(string):
if(string==string[::-1]):
print("The string is a palindrome")
else:
print("Not a palindrome")
stringpaline(a)
OUTPUT CASE 1:
OUTPUT CASE 2:
Not a palindrome
CODE :
OUTPUT :
7. Assign a different name to function and call it through the new name
CODE :
display("Kishan", 21)
show = display
show("Kishan", 21)
OUTPUT :
Kishan 21
Kishan 21