INTERNATIONAL INDIAN SCHOOL, RIYADH WORKSHEET …XI-XII Boys Section 8. Which method is used to...

14
Page 1 of 14 INTERNATIONAL INDIAN SCHOOL, RIYADH WORKSHEET (2020-2021) GRADE - XII COMPUTER SCIENCE SECOND TERM CH 1, 2 PYTHON REVISION TOUR I, II 1. 2. 3. 4. 5. Write the types of tokens: i) None ii) Break 6. Which of the following is not a valid arithmetic assignment operators? i) += ii)== iii) %= iv) //= 7. Write code (Python Library Module) to access value of pi to calculate area of a circle. 8. What type of objects can be used as keys in Dictionaries? 9. What are the two ways to remove something from a list? Write syntax also 10. Following code is trying to create a tuple with a single item, but gives error. What is the error and solution? >>>t(6) >>>len(t) 11.

Transcript of INTERNATIONAL INDIAN SCHOOL, RIYADH WORKSHEET …XI-XII Boys Section 8. Which method is used to...

  • Page 1 of 14

    INTERNATIONAL INDIAN SCHOOL, RIYADH

    WORKSHEET (2020-2021)

    GRADE - XII – COMPUTER SCIENCE – SECOND TERM

    CH 1, 2 – PYTHON REVISION TOUR – I, II

    1.

    2.

    3.

    4.

    5. Write the types of tokens: i) None ii) Break

    6. Which of the following is not a valid arithmetic assignment operators? i) += ii)== iii) %= iv) //=

    7. Write code (Python Library Module) to access value of pi to calculate area of a circle.

    8. What type of objects can be used as keys in Dictionaries?

    9. What are the two ways to remove something from a list? Write syntax also

    10. Following code is trying to create a tuple with a single item, but gives error. What is the error and solution?

    >>>t(6)

    >>>len(t)

    11.

  • Page 2 of 14

    12.

    13.

    14.

    15. Rewrite the following program after removing the syntactical errors.

  • Page 3 of 14

    16.

    CH 3 – WORKING WITH FUNCTIONS

    1. Can a function return multiple values? How?

    2. Explain with a code example the usage of default arguments and keyword arguments?

    3. What all information does a function header give you about the function?

    4. Differentiate between i) Fruitful and non-fruitful functions ii) Local and global variables iii) Actual and Formal parameters iv) Scope and Lifetime of a variable v) Arguments and Parameters

    5. Write a function that receives two string arguments and checks whether they are same length strings.(returns true in this case false otherwise)

    6. Write a function namely fun that takes no parameters and always returns None.

    7. Write a function that receives two numbers and generates a random number from that range and prints it.

  • Page 4 of 14

    8. Write a function that takes a positive integer and returns the ones position digit of the integer. Eg .if integer is 432, then the function should return 2.

    9. Write a program having a function that takes a number as argument and calculates cube for it. The function does not return a value. If there is no return value passed to the function in

    function call, the function should calculate cube of 2.

    10.

    11.

    CH 4 – RANDOM NUMBERS

    1.

    2.

  • Page 5 of 14

    3.

    4.

    5.

  • Page 6 of 14

    6.

    7.

  • Page 7 of 14

    8.

    9.

  • Page 8 of 14

    10.

    11.

  • Page 9 of 14

    12.

    CH 5 – FILE HANDLING 1. Write a method in python to read the content from a text file

    diary.txt line by line and display the same on screen.

    2. Write a method in Python to read lines from a text file DIARY.TXT, and display those lines, which are starting with an alphabet ‘P’.

    3. Write a method in Python to read lines from a text file INDIA.TXT, to find and display the occurrence of the word ‘‘India’’.

    4. Write a method in python to write multiple line of text contents into a text file daynote.txt line.

    5. Write a python program to find the longest line in a text file “Poem.txt”. 6. Write a python program to display only the digits in a text file. 7. Differentiate between the following:

    (1) f = open (‘diary. Txt’, ‘a’) (ii) f = open (‘diary. Txt’, ‘w’)

    8. Write a function countmy( )in Python to read the text file “DATA.TXT” and count the number of times “my” occurs in the file.

    9. Rewrite the following program after removing the syntactical errors.

    F = open(“a.txt”, ‘r’)

    line1 = ‘Welcome’

    F.write(line1)

    line2=”To K V Nagercoil”

    f.write(line2)

    f.close()

    10. Write a program to read a text file ‘Data.txt’ and find how many lines contain the word is (case to be ignored).All the lines containing the word ‘is’ should be

    Copied to a separate text file ‘Copy.txt’.

    11. Define a function that accepts a sentence and calculate the number of upper case letters and lower case letters

  • Page 10 of 14

    12. Write a function named “filter” that copies a text file “source.txt” onto “target.txt” abrring the lines starting with a “#” sign.

    13.

    CH 6 – RECURSION

    1. State the advantages and disadvantages of using recursion.

    2. What happens if the base condition isn’t defined in recursive programs?

    3. Write a python function to determine how many times a given letter occurs in a string recursively

    4. Fill in the line of code for calculating the factorial of a number.

    def fact(num):

    if num == 0:

    return 1

    else:

    return _____________________

    5.

  • Page 11 of 14

    CH 9 , 10 – DATA STRUCTURES – I , II

    1. In which operations of queue will you check whether the queue is empty or not?

    Write the python statement to check the empty condition for the queue.

    2. Differentiate between

    a) Stack and Queue

    b) Horizontal and vertical bar graph

    3. Which fundamental data structure in python do we use to implement a stack?

    4.

    5.

    6.

    7.

  • Page 12 of 14

    UNIT – 3 DATA MANAGEMENT

    1.

  • Page 13 of 14

    2.

    3. What is the command to retrieve data?

    4. What is the use of order by command?

    5. Differentiate between where and having clause.

    6. How can you view values by reducing redundant column?

    7. Differentiate between fetchall() and fetchone()

  • Page 14 of 14

    Prepared by:

    XI-XII Boys Section

    8. Which method is used to execute SQL query in python? Give example.

    9. Name the attribute which returns the number of rows affected on executing an

    SQL query via Python. Give the syntax and example.

    10. Which library is imported in the program implementing MySQL connectivity

    with Python?

    11. What is the use of commit() in python-mysql connectivity code? When and

    where is it used?

    12. Write down the steps to connect to a database in python. Give suitable example.