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()

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.

Looping Statement Test 5

  

Looping Statement Test 5

Q1. Write program to print the following pattern.

a.     1

1 2

1 2 3

1 2 3 4

 

b.     * * * *

* * *

* *

*

Q2. Accept 10 numbers from the user and display

    their average.

Q3. Write a program to print all prime numbers 

    that fall between two numbers(accept two 

    numbers from the user)

Q4. Write a program to display sum of odd numbers

    and even numbers that fall between 12 and 37

    (including both numbers)

Q5. Write a program to display all the numbers 

    which are divisible by 11 but not by 2 between

    100 and 500.

Q6. How many times the following loop execute?

c = 0

while c < 20:

           c += 2

Q7. Write the output of the following.

c = -9

while c < 20:

               c += 3

               print(c)

 

Q8. Write a program to print first 20 natural

    numbers except multiple of 2 & 3.

 

Q9. Write a program to print table of a number

    (accepted from user) in the following format.

    Like : input number is 7, so expected output  

    is

    7 * 1 = 7

    7 * 2 = 14 and so on

 

Q10. Write a program that keep on accepting number

     from the user until user enters Zero. 

     Display the sum and average of all the 

     numbers.

 

 

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