PGM 1 n=int(input('enter the number:')) c=0 a=1 b=1 while b0): sum=sum+num num=num-1 print("The sum of n natural number is:",sum) PGM 4 num=int(input("enter a number:")) for a in range(1,11): print(num,'x',a,'=',num*a) PGM 5 num =int(input('enter a number:')) flag = False if num==1: print(num,'is not a prime number') elif num > 1: for i in range(2, num): if (num % i)==0: flag = True break if flag: print(num,'is not a prime number') else: print(num,'is a prime number') PGM 6 def search(arr,n,key): for i in range(0,n): if(arr[i]==key): return i return -1 n=int(input('Enter the size = ')) arr=input('Enter the number = ').split() arr=[int(x)for x in arr] key=int(input('Enter the key Element to be searched = ')) n=len(arr) res=search(arr,n,key) if(res==-1): print('Element not found') else: print('Element foumnd at index =',res) PGM 7 def calculator(x, i, j): switcher={ 1:(i+j), 2:(i-j), 3:(i*j), 4:(i/j), } print(switcher.get(x,"wrong choice / Input")) print("simple calculator") print(" 1. Addition") print(" 2. Substraction") print(" 3. Multiplication") print(" 4. Division") x = input("please enter your choice:") i = input("please enter first number:") j = input("please enter second number:") print('result is:') calculator(int(x),int(i),int(j)) PGM 8 str1=input("enter the first string:-->") str2=input("enter the secand string:-->") print("Conversion of uppercase of",str1,"is",str1.upper()) print("Conversion of lowercase of",str2,"is",str2.lower()) print("swap-case of string",str1,"is",str1.swapcase()) print("the cased version of string",str1,"is",str1.title()) print("string replacement of first string",str1,"to",str1.replace(str1,str2)) string="python is awesome" capitalized_string=string.capitalize() print("old string:-->",string) print("Capitalized string is:->",capitalized_string) string="Python is awesome,isnt it?" substring="is" count=string.count(substring) print("the count of given string is:-->",count) name="bcacollege,nidsoshi" if name.isalpha()==True: print("all characters are alphabet") else: print("all characters are not alphabet") print("maximun is:-->",max(1,3,2,5,4)) num=[1,3,2,8,5,10,6] print("the maximun number is given arry is:->",max(num)) teststring="python" print("Length of",teststring,"is:->",len(teststring)) PGM 9 array=[] n=int(input('Enter the limit = ')) for i in range(n): element =int(input('Enter the element = ')) array.append(element) for i in range(n-1): min=i for j in range(i+1,n): if array[min]>array[j]: min=j if min !=1: temp=array[i] array[i]=array[min] array[min]=temp print('the sorted array in ascending order = ') for i in range(n): print(array[i]) PGM 10 stack = [] stack.append('1') stack.append('2') stack.append('3') print(stack) print('\n Elements poped from my_stack:') print(stack.pop()) print(stack.pop()) print(stack.pop()) print('\n my_stack after elements are poped:') print(stack) PGM 11 file = open("D:/myfile.txt","w") L = ['This is BCA College \n', 'Place is Nidasoshi \n', 'Fourth semester \n'] file.write("Hello Python\n") file.writelines(L) file.close() file = open("D:/myfile.txt","r+") print("Output of the Read function is ") print(file.read()) print() file.seek(0) print( "The output of the Readline function is ") print(file.readline()) print() file.seek(0) print("Output of Read(20) function is ") print(file.read(20)) print() file.seek(0) print("Output of Readline(20) function is ") print(file.readline(20)) print() file.seek(0) print("Output of Readlines function is ") print(file.readlines()) print() file.close() Comments