Showing posts with label String program. Show all posts
Showing posts with label String program. Show all posts

Computer Science - Informatics Practices Class XI/XII Python Module Solved Test Part 7

                                        

Computer Science - Informatics Practices Class XI/XII Python Module Solved Test  Part 7

Q1. Write a function in python that takes a list of words and returns the 

      word of longest length.

Q2. Write a function in python that takes a list of words and returns the 

       word which are starting from capital alphabet.

Q3. Write a function in python that takes a list of words and returns all the 

      words with last character in upper case.

Q4. Write a function in python that takes a string and convert all lower case

      alphabet to upper case and vice-versa.

Q5. Write a function in python that takes a string and replace all vowels by

      symbol "?".

Q6. Write a function in python that takes a string and count the characters 

      in upper case.

Q7. Write a function in python that takes a string and count the number of

       vowels.

Q8. Write a function in python that takes a string and count the number of 

      spaces.

Q9. Write a function in python that takes a string and count the number of

      digits in a string.

Q10. Write a function in python that takes a string and sub string and check

        whether a sub string is a part of string or not.


Solutions

Ans1:

def longword(a):
ln=0
for i in range(len(a)):
if ln<len(a[i]):
ln=len(a[i])
lwrd=a[i]
print("longest word is",lwrd)
longword(["Amit","Ashish","Anshuman"])

Output is : longest word is Anshuman

Ans 2
def capword(a):
for i in range(len(a)):
if a[i][0].isupper():
print("Result is",a[i])
capword(["amit","Ashish","anshuman"])

Output is : Result is Ashish

Ans 3:
def capword(a):
for i in range(len(a)):
if a[i][-1].isupper():
print("Result is",a[i])
capword(["amiT","Ashish","anshuman"])

Output is : Result is amiT

Ans 4:
def swapcase(a):
ns=''
l=len(a)
for i in range(l):
if a[i].isupper():
ns=ns+a[i].lower()
else:
ns=ns+a[i].upper()
print("Result is",ns)
swapcase("Subscribe to My Blog")

Output is: Result is sUBSCRIBE TO mY bLOG

Ans 5:

def swapvow(a):
ns=''
l=len(a)
for i in range(l):
if a[i] in "aeiouAEIOU":
ns=ns+'?'
else:
ns=ns+a[i]
print("Result is",ns)
swapvow("Subscribe to My Blog")

Output is : Result is S?bscr?b? t? My Bl?g

Ans 6:

def countupper(a):
c=0
l=len(a)
for i in range(l):
if a[i].isupper():
c=c+1
print("Result is",c)
countupper("Subscribe to My Blog")

Output is : Result is 3

Ans 7:
def countvowel(a):
c=0
l=len(a)
for i in range(l):
if a[i] in "aeiouAEIOU":
c=c+1
print("Result is",c)
countvowel("Subscribe to My Blog")

Output is : Result is 5

Ans 8:

def countspace(a):
c=0
l=len(a)
for i in range(l):
if a[i].isspace():
c=c+1
print("Result is",c)
countspace("Subscribe to My Blog")

Output is : Result is 3

Ans 9:
def countdigit(a):
c=0
l=len(a)
for i in range(l):
if a[i].isdigit():
c=c+1
print("Result is",c)
countdigit("Subscribe 2 My Blog 123")

Output is : Result is 4

Ans 10:

def checksub(a,b):
if b in a:
print("Result is","Present")
else:
print("Result is","not present")
checksub("Subscribe to My Blog",'to')

Output is : Result is Present


Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet