PRACTICAL 1.
Q1 (A) WAP in python to display the variable types of at least
3 different variables.
SOL:
a=10
b=10.5
c="Hello"
print(type(a))
print(type(b))
print(type(c))
OUTPUT:
<class 'int'>
<class 'float'>
<class 'str'>
Q1 (B) WAP to accept 3 numbers from the user and display
the sum of squares of those numbers.
SOL:
a=int(input("Enter number: "))
b=int(input("Enter number: "))
c=int(input("Enter number: "))
x=a*a
y=b*b
Z=C*C
d=x+y+z
print("Sum of square is ",d)
OUTPUT:
Enter number: 45
Enter number: 54
Enter number: 65
Sum of square is 9166
Q1 (C) WAP to demonstrate:-
(i) If-else statement:
a=45
if a>0:
print(a,' is positive')
else:
print(a,' is negative')
OUTPUT:
45 is positive
(ii) If-elif-else statement :
a=6
b=5
c=9
if a>b and a>c:
print (a, 'is largest')
elif a<b and b>c:
print (b, 'is largest')
else:
print (c, 'is largest')
OUTPUT:
9 is largest
Q1 (D) WAP to demonstrate while loop to display a statement
recursively.
SOL:
i=0
while i<6:
print("I am studying Bsc IT")
i+=1
OUTPUT:
I am studying Bsc IT
I am studying Bsc IT
I am studying Bsc IT
I am studying Bsc IT
I am studying Bsc IT
I am studying Bsc IT
Q1 (E) WAP to demonstrate local and global variables.
SOL:
a=101
print(a)
def display():
a="In function"
print(a)
display()
print(a)
OUTPUT:
101
In function
101
PRACTICAL 2.
Q2 (A) Create a user-defined parameterized function for
finding the area of a cylinder.
SOL:
def area(r,h):
a=3.14*r*r*h
print("Area of cylinder is ",a)
p=float(input("Enter radius: "))
s=float(input("Enter height: "))
area(p,s)
OUTPUT:
Enter radius: 3
Enter height: 3.2
Area of cylinder is 90.432
Q2 (B) WAP to demonstrate function with return types.
(Fruitful Function)
SOL:
def sum(a,b,c):
x=a*a*a+b*b*b+c*c*c
return x
d=sum(2,3,5)
print('Sum of cube of three numbers is ',d)
OUTPUT:
Sum of cube of three numbers is 160
Q2 (C) Create functions in python for odd, even and factorial.
SOL:
def factorial(n):
if n==0:
return 1
else:
return n*factorial(n-1)
def even_odd(num):
if num%2==0:
return "Even"
else:
return "Odd"
number=3
print(number,"is",even_odd(number))
number=8
print("Factorial of", number, "is", factorial(number))
OUTPUT:
3 is Odd
Factorial of 8 is 40320