Practicals Class 11 Term 2 Final
Practicals Class 11 Term 2 Final
"""
def selection():
arr = [20,9,16,3,5]
n = len(arr)
for i in range(n-1):
pos_smallest = i
for j in range(i+1, n):
if arr[j] < arr[pos_smallest]:
pos_smallest = j
arr[i], arr[pos_smallest] = arr[pos_smallest], arr[i]
print('Array after sorting')
print(arr)
def insertion():
arr = [20,9,16,3,5]
for i in range(1,len(arr)):
j=i
while arr[j-1]>arr[j] and j>0:
arr[j-1], arr[j] = arr[j] , arr[j-1]
j-=1
print("THE LIST AFTER SORTING:" , arr)
print("*"*80)
print("\t\t\t\tSorting")
print("*"*80)
ch='Y'
while ch=='Y':
print("\t\t 1. Selection Sort")
print("\t\t 2. Insertion Sort")
choice=int(input("Enter the Option 1/2:"))
if choice==1:
selection()
elif choice==2:
insertion()
print("\nDo u want to continue??")
ch=input("Enter Y/N:")
if ch=='N':
break
"""
print("*"*80)
print("\t\t\t\tConvert Binary to decimal and Decimal to Binary")
print("*"*80)
ch='Y'
while ch=='Y':
print("\t\t 1.Convert Binary to decimal")
print("\t\t 2. Convert Decimal to Binary")
choice=int(input("Enter the Option 1/2:"))
if choice==1:
BtoD()
elif choice==2:
DtoB()
print("\nDo u want to continue??")
ch=input("Enter Y/N:")
if ch=='N':
break
"""
"""
def addEmployee():
num = int(input("Enter the number of employees whose data to be stored: "))
count = 1
while count <= num:
EmpCode=input("Enter the Employee_Code:")
name = input("Enter the name of the Employee: ")
dep=input("Enter the name of Department:")
Gender=input("Enter Gender:")
salary = int(input("Enter the salary: "))
employee[EmpCode] = [name,dep,Gender,salary]
count += 1
print(employee)
print("\n\nEMPLOYEE_nAME\tSALARY")
for k in employee:
print(k,'\t\t',employee[k][3])
def searchEmployee():
search=input("\t\tSearch by Code/Name/dep/Gender:")
for i in employee:
if i==search:
print(i,"\t\t",employee[i])
elif employee[i][0]==search:
print(i,"\t\t",employee[i])
elif employee[i][1]==search:
print(i,"\t\t",employee[i])
elif employee[i][2]==search:
print(i,"\t\t",employee[i])
def UpdateEmployee():
update=input("\t\t Enter Name/dep/Gender to be modified:")
Newvalue=input("\t\t Enter NewValue:")
for i in employee:
if employee[i][0]==update:
employee[i][0]=Newvalue
print("\n\t\tModified Value:")
print(i,"\t\t",employee[i])
elif employee[i][1]==update:
employee[i][1]=Newvalue
print("\n\t\tModified Value:")
print(i,"\t\t",employee[i])
elif employee[i][2]==update:
employee[i][2]=Newvalue
print("\n\t\tModified Value:")
print(i,"\t\t",employee[i])
print("*"*80)
print("\t\t\t\t Employee Management")
print("*"*80)
employee = dict()
ch='Y'
while ch=='Y':
print("\t\t 1. Add Employee")
print("\t\t 2. Search")
print("\t\t 3. Update")
choice=int(input("Enter the Option 1/2:"))
if choice==1:
addEmployee()
elif choice==2:
searchEmployee()
elif choice==3:
UpdateEmployee()
print("\nDo u want to continue??")
ch=input("Enter Y/N:")
if ch=='N':
break
"""
#PG4:Cities
"""Make a dictionary called cities. Use the names of three cities as keys in
your dictionary. Create a dictionary of information about each city and
include the country that the city is in, its approximate population, and
one fact about that city. The keys for each city’s dictionary should be
something like country, population, and fact. Print the name of each city
and all of the information you have stored about it."""
"""
cities = {
'santiago': {
'country': 'chile',
'population': 6158080,
'nearby mountains': 'andes',
},
'talkeetna': {
'country': 'alaska',
'population': 876,
'nearby mountains': 'alaska range',
},
'kathmandu': {
'country': 'nepal',
'population': 1003285,
'nearby mountains': 'himilaya',
}
}
#PG5:Write a Python Program to check if the two strings are anagram and Sort Words
in Alphabetical Order
"""
def anagram():
s1=input("Enter first string:")
s2=input("Enter second string:")
if(sorted(s1)==sorted(s2)):
print("The strings are anagrams.")
else:
print("The strings aren't anagrams.")
def sorting():
str_1 = input ("Enter a string")
words=[]
for word in str_1.split():
word.lower()
words.append(word)
words.sort ()
print ("The words sorted in alphabetical order are as follows:")
for word in words:
print (word)
print("*"*80)
ch='Y'
while ch=='Y':
print("\t\t 1. Anagram")
print("\t\t 2. Sorting")
choice=int(input("Enter the Option 1/2:"))
if choice==1:
anagram()
elif choice==2:
sorting()
print("\nDo u want to continue??")
ch=input("Enter Y/N:")
if ch=='N':
break
"""
# 6 WAP to print the Fibonacci series of n terms., factorial, Armstrong no.
"""
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** len(str(num))
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
num = 10
n1, n2 = 0, 1
print("Fibonacci Series:", n1, n2, end=" ")
for i in range(2, num):
n3 = n1 + n2
n1 = n2
n2 = n3
print(n3, end=" ")
print()
"""
def pattern1(rows):
for i in range(1, rows+1):
for j in range(rows,0,-1):
if j >i:
print(" ", end=" ")
else:
print(j,end=" ")
print()
pattern1(5)
def pattern2():
x=64
for row in range (1,6):
for col in range (1,11):
print(" ",end=" ")
if row+col==6 or col-row==4:
x+=1
print(chr(x),end="")
elif row==5:
x+=1
print(chr(x),end="")
else:
print(end=" ")
print()
pattern2()
"""
"""
# 10 Python program to print perfect numbers from the given list of integers
"""
plist=[]
n=int(input('no of terms:'))
list=[]
for i in range(n):
a= float(input('enter a number:'))
list.append(a)
temp = a**0.5
temp1=temp//1
if temp1<temp and temp1+1>temp:
continue
else:
plist.append(a)
print(plist)
"""