Main Code
Main Code
SOURCE CODE :
OUTPUT :
ff
QUESTION 2 :
SOURCE CODE:
OUTPUT :
fl
fl
ff
QUESTION 3 :
SOURCE CODE :
def subString(Str,n):
# Pick starting point
for Len in range(1,n + 1):
# Pick ending point
for i in range(n - Len + 1):
j = i + Len - 1
for k in range(i,j + 1):
print(Str[k],end="")
print()
Str = "word"
subString(Str,len(Str))
OUTPUT :
QUESTION 4 :
SOURCE CODE:
a = 50
b = 67
c = 79
s = (a + b + c) / 2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
OUTPUT :
QUESTION 5 :
Write a python program to print a number is positive/negative using if-else
SOURCE CODE :
OUTPUT :
fl
QUESTION 6 :
Write a python program to create, append and remove lists in python.
SOURCE CODE :
class check():
def __init__(self):
self.n=[]
def add(self,a):
return self.n.append(a)
def remove(self,b):
self.n.remove(b)
def dis(self):
return (self.n)
obj=check()
choice=1
while choice!=0:
print("0. Exit")
print("1. Add")
print("2. Delete")
print("3. Display")
choice=int(input("Enter choice: "))
if choice==1:
n=int(input("Enter number to append: "))
obj.add(n)
print("List: ",obj.dis())
elif choice==2:
n=int(input("Enter number to remove: "))
obj.remove(n)
print("List: ",obj.dis())
elif choice==3:
print("List: ",obj.dis())
elif choice==0:
print("Exiting!")
else:
print("Invalid choice!!")
print()
OUTPUT :
QUESTION 7 :
SOURCE CODE :
OUTPUT :
QUESTION 8:
Demonstrate a python code to print try, except and nally block statements
SOURCE CODE:
def divide(x, y):
try:
result = x // y
print("Yeah ! Your answer is :", result)
except ZeroDivisionError:
print("Sorry ! You are dividing by zero ")
divide(9, 2)
divide(3, 1)
OUTPUT:
QUESTION 9 :
SOURCE CODE:
num = 3
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
OUTPUT:
fi
fi
QUESTION 10 :
SOURCE CODE:
lis = [2, 7, 3, 9, 4, 3, 8]
del lis[2 : 5]
print ("List elements after deleting are : ",end="")
for i in range(0, len(lis)):
print(lis[i], end=" ")
print("\r")
lis.pop(2)
print ("List elements after popping are : ", end="")
for i in range(0, len(lis)):
print(lis[i], end=" “)
OUTPUT:
QUESTION 11:
a) Add items
b) len()
c) check for item in tuple
SOURCE CODE :
Tuple1 = ()
print("Initial empty Tuple: ")
print(Tuple1)
Tuple1 = ('aryamnn', 'For')
print("\nTuple with the use of String: ")
print(Tuple1)
list1 = [1, 2, 4, 5, 6]
print("\nTuple using List: ")
print(tuple(list1))
Tuple1 = tuple('aeiou')
print("\nTuple with the use of function: ")
print(Tuple1)
OUTPUT :
QUESTION 13:
SOURCE CODE:
OUTPUT :
fi
QUESTION 14:
Source Code :
def convert(s):
new = ""
for x in s:
new += x
return new
s = ['A', 'R', 'Y', 'A', 'M', 'N', 'N', 'S', 'A', 'B', 'L', 'O', 'K']
print(convert(s))
OUTPUT :
QUESTION 16:
Source Code :
celsius = 42.5
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
OUTPUT :
QUESTION 17:
Write a program to insert 5 elements into an array and display the elements of
the array
Source Code :
OUTPUT :
fi
QUESTION 18 :
Write a python program to check if the year entered by the user is a leap year or
not.
Source Code :
year = 2210
OUTPUT :
QUESTION 19 :
Write a Python Program to Display First 10 Numbers Using while Loop Starting
from 0.
Source code :
i=1
while(i<=10):
print(i)
i += 1
QUTPUT :
QUESTION 20 :
Source code :
setn = {5, 10, 3, 15, 2, 20}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nLength of the said set:")
print(len(setn))
setn = {5, 5, 5, 5, 5, 5}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nLength of the said set:")
print(len(setn))
setn = {5, 5, 5, 5, 5, 5, 7}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nLength of the said set:")
print(len(setn))
OUTPUT
ff
QUESTION 21 :
Write a program for lter() to lter only even numbers from a given list.
Source code :
# Python code to lter even values from a list
# Initialisation of list
lis1 = [1,2,3,4,5]
is_even = lambda x: x % 2 == 0
# using lter
lis2 = list( lter(is_even, lis1))
# Printing output
print(lis2)
OUTPUT :
fi
fi
fi
fi
fi
QUESTION 22 :
Write a python program to nd factorial of a number using recursion and without
recursion.
SOURCE CODE :
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 7
Output :
fi
QUESTION 23 :
Write a program to double a given number and add two numbers using
lambda()?
SOURCE CODE :
multi = lambda a, b : a * b
print(multi(5, 20))
return a * b
print(multi_func(5, 20))
OUTPUT :
QUESTION 24 :
Write a program for map() function to double all the items in the LIST ?
SOURCE CODE :
# of map.
# Return double of n
def addition(n):
return n + n
numbers = (1, 2, 3, 4)
print(list(result))
OUTPUT :
QUESTION 25 :
Write a program to nd sum of the numbers for the elements of the list by using
reduce()?
SOURCE CODE :
import itertools
import functools
# initializing list
OUTPUT :
fi