Showing posts with label Class XI - Python. Show all posts
Showing posts with label Class XI - Python. 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


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

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

Q1. Name the module to be imported for using mathematical functions.

Q2. Name the module to be imported for generating random numbers.

Q3. Name the module to be imported for text manipulation functions.

Q4. Write the value of the following (till 2 decimal places)

>>> import math

>>>print(math.pi)

>>>print(math.e)

Q5. Name two angle conversion methods of math module.

Q6. degree and radians are functions of _____________ module.

Q7. Write a program in python to find the roots of a quadratic equation.

A quadratic equation is of the form: ax2 + bx + c

Accept values of a, b and c from user.

formula of finding root is: x = [-b +/- sqrt(b2 - 4ac)]/2a

Q8. Write a program to accept angle in degree and convert it into radian.

Q9. Write a python program to convert binary number to decimal number

Q10. Write a python program to convert decimal number to binary.

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

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

Q1. Write the output of following code.

CODE

OUTPUT

a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

 


a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

print(a)

 


a = 10

def fun():

  global a

  a=a+2

  print(a)

fun()

print(a)

 


a = 10

def fun():

  global a

  a=a+2

  print(a)

print(a)

fun()

 

 

 


Q2. Write the output of the following:
a = 10
def fun():
global a
a=a+2
print(a)
fun()
print(a)

Q3. Write the output of the following
a = 10
print(a+3)
def fun():
global a
a=a+2
print(a)
fun()
print(a)

Q4. Write the output of the following.
a = 10
print(a*3)
def fun():
print(a)
fun()
print(a)

Q5. Write the output of the following.
a = 10
print(a*3)
def fun(a):
print(a*2)
fun(a)
print(a)

Q6. Write the output of the following:
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Q7. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Q8. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
print("hello")
print("hello")
fun1(a)
print(a)



                                            SOLUTION

Q1. Write the output of following code.

CODE

OUTPUT

a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

 

11

a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

print(a)

 

11

10

a = 10

def fun():

  global a

  a=a+2

  print(a)

fun()

print(a)

 

12

12

a = 10

def fun():

  global a

  a=a+2

  print(a)

print(a)

fun()

 

 

10

12 


Q2. Write the output of the following:
a = 10
def fun():
global a
a=a+2
print(a)
fun()
print(a)

Ans
10
12

Q3. Write the output of the following
a = 10
print(a+3)
def fun():
global a
a=a+2
print(a)
fun()
print(a)
Ans.
13
10
12

Q4. Write the output of the following.
a = 10
print(a*3)
def fun():
print(a)
fun()
print(a)

Ans.
30
10
10

Q5. Write the output of the following.
a = 10
print(a*3)
def fun(a):
print(a*2)
fun(a)
print(a)

Ans.
30
20
10

Q6. Write the output of the following:
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Ans.
30
20
hello
10

Q7. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Ans.
30
hello
20
hello
10

Q8. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
print("hello")
print("hello")
fun1(a)
print(a)

Ans.
30 hello hello 20 hello hello 10

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

 

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

Q1. Write a code to print today’s date. 

Q2. How can you separate year, month and day from current 

    date?

Q3. today() function belongs to __________ class of 

     datetime module.

Q4. Which attribute return hour from datatime object?

Q5. Which attribute return day from datatime object?

Q6. time class of datetime module holds attributes for 

    hours, minutes, second and microsecond. (T/F)

Q7. What is the function of now() method.

Q8. Name two methods of datatime module.

Q9. ________ attribute returns month from ____ object.

Q10. Write the code to display current date and time.


 SOLUTION:

 

Python Module Test 3

Q1. Write a code to print today’s date.

Ans. import datetime

td=datetime.date.today()

print(td)

 Q2. How can you separate year, month and day from current 

     date?

Ans.

import datetime

td=datetime.date.today()

print(td.year)

print(td.month)

print(td.day)

 Q3. today() function belongs to __________ class of 

     datetime module.

Ans. date

Q4. Which attribute return hour from datatime object?

Ans. hour

Q5. Which attribute return day from datatime object?

Ans. day

Q6. time class of datetime module holds attributes for 

    hours, minutes, second and microsecond. (T/F)

Ans. True

Q7. What is the function of now() method.

Ans. This method returns the current date and time.

Q8. Name two methods of datatime module.

Ans. today() and now()

Q9. ________ attribute returns month from ____ object.

Ans. month, datetime

Q10. Write the code to display current date and time.

Ans.

import datetime
td=datetime.datetime.now()
print(td)

 

Computer Science - Informatics Practices Class XI/XII Python Dictionary Solved Test Part 5

Computer Science - Informatics Practices Class XI/XII Python Dictionary Solved Test  Part 5

Q1. Explain the following functions in reference to dictionary.

a. items()

b. keys()

c. values()

Q2. Write the output of the following:

a={1:10,2:20,3:30}
b={3:35,4:40}
print(a.items())
print(a.keys())
print(a.values())

Q3. Write a program to store details like book
number, author name and price in dictionary.

Q4. To delete an element from dictionary, we can
use either _______ statement of ______ method.

Q5. What is the difference between list and
dictionary?
Q6. Why list can not be used as keys in dictionary?

Q7. a={1:10,2.5:20,3:30,4:40,5:50}
Find errors in the following and write the correct
statement
  1. a(6) = 60
  2. a.len()
  3. a.clears()
  4. a.gets(3)
  5. a.item()
  6. a.valueS()
  7. a.keyS()
  8. a.del(4)
  9. pop(4)

                 SOLUTIONS

Q1. Explain the following functions in reference

to dictionary.

a. items()

b. keys()

c. values()

Ans. a. items() : This method returns the content

of dictionary as a list of tuples having key-value

pairs.

 b. keys() : It returns the list of key values in

dictionary.

 c. values(): It returns the list of values from

dictionary.

Q2. Write the output of the following:

a={1:10,2:20,3:30}
b={3:35,4:40}
print(a.items())
print(a.keys())
print(a.values())

Ans. dict_items([(1, 10), (2, 20), (3, 30)])      dict_keys([1, 2, 3]) dict_values([10, 20, 30])
Q3. Write a program to store details like book
number, author name and price in dictionary.
Ans. b={}
n=int(input("Enter number of records to enter"))
for i in range(n):
bno=int(input("Enter book number"))
bn=input("Enter book name")
pr=int(input("Enter price"))
t=(bn,pr)
b[bno]=t
print(b)

Q4. To delete an element from dictionary, we can
use either _______ statement of ______ method.
Ans. del, pop()

Q5. What is the difference between list and
dictionary?

List

Dictionary

Elements are enclosed in square brackets

Elements are enclosed in curly braces

Index value is an integer only

Index value can be of any type.

Q6. Why list can not be used as keys in dictionary?
Ans. Because list are mutable.

Q7. a={1:10,2.5:20,3:30,4:40,5:50}
Find errors in the following and write the correct
statement
  1. a(6) = 60
  2. a.len()
  3. a.clears()
  4. a.gets(3)
  5. a.item()
  6. a.valueS()
  7. a.keyS()
  8. a.del(4)
  9. pop(4)
Ans.
  1. a[6]=60
  2. len(a)
  3. a.clear()
  4. a.get(3)
  5. a.items
  6. a.values()
  7. a.keys()
  8. del a[4]
  9. a.pop(4)

Computer Science - Informatics Practices Class XI/XII Python Dictionary Solved Test Part 4

Computer Science - Informatics Practices Class XI/XII Python Dictionary Solved Test  Part 4


Q1.  d1 = {1 : 'One' , 2 : "Two", 3 : "Three"}

        d2 = { 5 : "Five", 6 : "Six"}

Write the code of the following, in reference to the above dictionary

a. Write a for loop to print only keys of d1.

b. Write a for loop to print only values of d1.

c. Write a for loop to print both keys and values of d1 in the following format.

          1-------One

          2------Two

d. Add one more pair (4 : "Four") in d1

e. Modify the value of key 2. (make it "Too" in place "Two") 

f. Merge d1 and d2 in d1.

Q2. What do you mean by update() function in dictionary?

Q3. Write the output of the following code :


Q4. What is the difference between del command and pop() function in context of 
      dictionary?

Q5.  a={1:10,2:20,3:30}

  1. Write code to delete the second element using del command.
  2. Write code to delete the third element using pop() function.
Q6. Write the output of the following code.

                a={1:10,2:20,3:30}

        b={3:35,4:40}
        print(1 in a)
        print(3 in b)
        print(4 in a)
        print(max(a))
        print(min(a))
        print(max(b))
        print(min(b))
        print(sum(a))
        print(sum(b))
        print(len(b))
        print(len(a))

Q7. What do you mean by clear() function in reference to dictionary?

Q8. get() method returns ______(key or value) in dictionary.?

Q9. get() method returns ______, if key does not
exist in dictionary.

Q10. get() method takes the key or value as
argument.

                          

SOLUTION


Q1.  d1 = {1 : 'One' , 2 : "Two", 3 : "Three"}

        d2 = { 5 : "Five", 6 : "Six"}

Write the code of the following, in reference to the above dictionary

a. Write a for loop to print only keys of d1.

b. Write a for loop to print only values of d1.

c. Write a for loop to print both keys and values of d1 in the

following format.

          1-------One

          2------Two

d. Add one more pair (4 : "Four") in d1

e. Modify the value of key 2. (make it "Too" in place "Two") 

f. Merge d1 and d2 in d1.

Ans. a. for i in d1:

print(i)

b. for i in d1:

print(a[i])

c. for i in d1:

print(i,"------",a[i])

d. d1[4]="Four"

e. d1[2] = 'Too'

f. d1.update(d2)

Q2. What do you mean by update() function in dictionary?

Ans. update() function is used to merge two dictionaries

into one dictionary

Q3. Write the output of the following code :



Ans. {1:10,2:20,3:30}
{3:35,4:40}
{1:10,2:20,3:35,4:40}
{3:35,4:40}
Q4. What is the difference between del command and pop()
function in context of dictionary?
Ans. pop() method return the deleted element while del statement
does not return the deleted element.

Q5.  a={1:10,2:20,3:30}

  1. Write code to delete the second element using del command.
  2. Write code to delete the third element using pop() function.
Ans 1. del(a[2])
2. a.pop(3)
Q6. Write the output of the following code.

                a={1:10,2:20,3:30}

        b={3:35,4:40}
        print(1 in a)
        print(3 in b)
        print(4 in a)
        print(max(a))
        print(min(a))
        print(max(b))
        print(min(b))
        print(sum(a))
        print(sum(b))
        print(len(b))
        print(len(a))
Ans.
        True         True         False         3         1         4         3         6         7         2         3
Q7. What do you mean by clear() function in
reference to dictionary?
Ans. clear() function removes all the elements from dictionary.

Q8. get() method returns the key or a value
in dictionary.
Ans. get() method returns a value for the given key.

Q9. get() method returns ______, if key does not
exist in dictionary.
Ans. None

Q10. get() method takes the key or value as
argument.
Ans. key


Looping Statement Test 6

 

Looping Statement Test 6

Q1. Write a program to print the following pattern

5 5 5 5 5

4 4 4 4

3 3 3

2 2

1

Q2. Find errors in the following code:

a = int(“Enter any number”)

for i in Range[2,6]

    if a=i

      print(“A”)

    else

      print(“B”)

Q3. Write a program to accept decimal number

    and display its binary number.

Q4. Accept a number and check whether it is

    palindrome or not.

Q5. Write a program to accept a number and check whether it is a perfect number or not.

(Perfect number is a positive integer which is equal to the sum of its divisors like divisors of 6 are 1,2,3, and sum of divisors is also 6, so 6 is the perfect number)

Q6. Write a program to find the sum of the following series(accept values of x and n from user)

1 + x/1! + x2/2! + ……….xn/n!

Q7. Write a program to print the following pattern

A

B C

D E F

G H I J

K L M N O

Q8. Write a program to find the sum of following (Accept values of a, r, n from user)

a + ar + ar2 + ar3 + ………..arn

Q9. for x in range(10,20):

      if (x%2==0):

           continue

       print(x)

Q10. Write a function to display prime numbers below 25.

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