rohidas

Hi I am Rohidas lande.I have teaching in C.D.jain college of commerce Shrirampur .I have Nine year in teaching Experience to teach various programming langauge,script languages,databases like Java,C,C++,php,python,html,css,javascript,mysql,oracle.

Python_Assignment2

Savitribai Phule Pune University T. Y. B. B. A. (C. A.) Semester-V (CBCS 2019 Pattern) CA-506: Lab Book Credits-03 Assignment 2: Working with Strings and List
Sr.NoAssignment name
Set-A
1
Write a python script which accepts 5 integer values and prints “DUPLICATES”if any of the values entered are duplicates otherwise it prints “ALL UNIQUE”. Plz Click on Question to see Answer

a=[] n=int(input("Enter limit:")) for i in range(0,n): val=input("Enter number:") a.append(val) flag=0 for val in a: if a.count(val)!=1: flag=1 if flag==0: print("UNIQUE") else: print("DUPLICATE")


2
Write a python script to count the number of characters (character frequency) in a string. Sample String : google.com'. Expected Result : {'o': 3, 'g':2, '.': 1, 'e': 1, 'l': 1, 'm': 1, 'c': 1} Plz Click on Question to see Answer

d={} s=input("Enter a string") for ch in s: if ch in d: d[ch]+=1 else: d[ch]=1 print(d)


3
Write a Python program to remove the characters which have odd index values of a given string. Plz Click on Question to see Answer

c=input("Enter String") ch="" for i in range(len(c)): if i%2==0: ch=ch+c[i] print(ch)


4
Write a program to implement the concept of stack using list. Plz Click on Question to see Answer

a=[10,20,30,40,50] print("List=",a) a.append(60) print("Push element in list=",a) val=a.pop() print("poped values=",val) print("After pop element in the list=",a)


5
Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself. Sample String: 'restart' Plz Click on Question to see Answer

s=input("Enter a string") res=s[0]+s[1:]].replace(s[0],'$') print(str(res))


Set-B
1
Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string. If the string length is less than 2,return instead of the empty string. Sample String : 'General12' Expected Result : 'Ge12' Sample String : 'Ka' Expected Result : 'KaKa' Sample String : ' K' 18 Expected Result : Empty String.

Plz Click on Question to see Answer


s=input("Enter string") if len(s)<2: print("Empty String") else: print("string=",s[0:2],s[len(s)-2:len(s)])


2
Write a Python program to get a single string from two given strings,separated by a space and swap the first two characters of each string. Sample String : 'abc', 'xyz' Expected Result : 'xycabz'. Plz Click on Question to see Answer

s=input("Enter String:") for i in range(0,len(s)): if s[i]==' ': s2=s[i+1:i+3]+s[2:i]+s[0:2]+s[i+3:] print(s2)


3
Write a Python program to count the occurrences of each word in a given sentence. Plz Click on Question to see Answer

s=input("Enter String:") w=input("Enter word:") a=[] count=0 a=s.split(" ") for i in range(0,len(a)): if(w==a[i]): count=count+1 print("count of the word is:") print(count)


4
Write a program to implement the concept of queue using list Plz Click on Question to see Answer

q=[] q.append('a') q.append('b') q.append('c') print("Initial queue") print(q) print("\n dequeue from queue") print(q.pop(0)) print(q.pop(0)) print(q.pop(0)) print("after removing elements from quue") print(q)


5
Write a python program to count repeated characters in a string. Sample string: 'thequickbrownfoxjumpsoverthelazydog' Expected output: o 4 e 3 u 2 h 2 r 2 t 2 Plz Click on Question to see Answer

s=input("enter string") d={} for ch in s: if ch in d: d[ch]=d[ch]+1 else: d[ch]=1 print(d)


Set-C
1
Write a binary search function which searches an item in a sorted list. The function should return the index of the elements to be searched in the list. Plz Click on Question to see Answer

def search(a,num,n): top=0 bottom=n-1 flag=0 while top<=bottom: mid=int(top+bottom/2) if a[mid]==num: flag=1 break if num>a[mid]: top=mid+1 if num


Post a Comment

0 Comments