Showing posts with label Module. Show all posts
Showing posts with label Module. 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 5

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

Q1. Name the library which is to be imported to use the following functions.

a. log()                            b. pow()

Q2. Create a module temp.py which contain the following functions.

a. ctk()  #which converts degree celsius to kelvin.

b. ctf()  #which converts degree celsius to fahrenheit.

Q3. Write a function in2f() in python which takes input in inches and display result in feet. [1feet = 15inches]

Q4. Write the output of the following:

import math

print(math.floor(7.2))

Q5. How modules and packages are related to each other?

Q6. Create a module vol.py which contains the following functions.

a. volcyl() # which calculates volume of cylinder.

b. volcube() # Which calculate volume of cube.

c. volcuboid() #Which calculates volume of cuboid

Q7. What is library in python?

Q8. State the difference between import math and from math import* 


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 Module Solved Test Part 2

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

Q1. Code of accessing object obj1 from module 'mod' is obj1.mod or mod.obj1.


Q2. What do you mean by namespace in python?

Q3. Name three namespaces in python.

Q4. Write full form of LEGB.

Q5. import calc as c
       What is calc and c in above statement?

Q6. from calc import c1, c2
       What is c1 and c2 in above statement?

Q7. from calc import c1 as c
       What is c1 and c in above statement?

Q8. Create a module named calc and define two functions named sum() and prod() which takes two numbers as argument and calculate sum and product.

Q9. Python supports ________ format for date.

Q10. Name the module which contains today() method.

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

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

Q1. What do you mean by module in python?

Q2. Approach of breaking a large program into smaller modules is 
       called ______________.

Q3. A library in python refers to the collection of ____________.

Q4. Extension of module is ________________.

Q5. What do you mean by main module?

Q6. __________ statement can be used to import module.

Q7. Write a statement to import a module named 'calc'.

Q8. Methods in a module can be accessed by syntax __________.

Q9. Name a function which is used to display all objects of module.

Q10. There is a module named 'calc' which includes three 
         sub-modules.
  • calc_1()
  • calc_2()
  • calc_3()
Write three ways to import module calc or a sub-module calc_2()

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