Tamil Solution

Educational News | Recruitment News | Tamil Articles

Uncategorized

12th Computer Science 2nd Assignment July 2021 Answerkey

12th Computer Science 2nd Assignment July 2021 Answerkey :- Here is the full answerkey for 12th standard computer science second assignment for english and tamil medium students. Students can download it using the google drive link shared in this page

12th Computer Science English Medium 2nd Assignment July 2021 Answerkey

  • Download 12th Computer Science English Medium second assignment pdf only questions – Download Now
  • Download 12th Computer Science English Medium assignment pdf with answers

12th Computer Science Tamil Medium 2nd Assignment July 2021 Answerkey

  • Download 12th Computer Science Tamil Medium second assignment pdf only questions – Download Now
  • Download 12th Computer Science Tamil Medium assignment pdf with answers only questions – Visit This Page

ASSIGNMENT

CLASS : XII SUBJECT : COMPUTER SCIENCE

UNIT II

CHAPTER 5: PYTHON – VARIABLES AND OPERATORS

PART I


Multiple Choice Questions:


Who developed Python?


a. Ritche

b. Guido Van Rossum

c. Bill Gates

d. Sundar Pitchai

Answer :- b. Guido Van Rossum


The Python Prompt that indicates the interpreter is ready to accept
instruction is …………….


a. >>>

b. <<<

c. #

d. <<

Answer:- a. >>>


Which of the following shortcut is used to create a new Python Program?


a) Ctrl + C
b) Ctrl + F
c) Ctrl + B
d) Ctrl + N

Answer :- d) Ctrl + N


Which of the following shortcut is used to save Python program?


a. Ctrl+S

b. Ctrl+V

c. Ctrl+C

d. Ctrl+N

Answer :- a. Ctrl+S


Python files are saved with extension ………….


a. .py

b. .pr

c. .pq

d. .ps

Answer :- a. .py


This symbol used to print more than one item on a single line is …………


a. Semicolon(;)

b. Dollar($)

c. Comma(,)

d. Colon(:)

Answer :- c) commaQ


Which of the following Character is used to give comments in Python program?


a. #

b. &

c. @

d. $

Answer :- a. #

Which operator is also called as comparative operator?


a. Arithmetic

b. Relational

c. Logical

d. Assignment

Answer :- b. Relational


Which Operator is also called as Conditional Operator?


a. Ternary

b. Relational

c. Logical

d. Assignment

Answer :- a. Ternary

Which function is used to display result on the screen?


a. print( )

b.input ( )

c. sum ( )

d. mult ( )

Answer :-
a. print( )



PART II

Very short Answer :

1.What are the different modes that can be used to test Python Program?

In Python, programs can be written in two ways namely Interactive mode and Script mode. The Interactive mode allows us to write codes in Python command prompt (>>>) whereas in script mode programs can be written and stored as separate file with the extension .py and executed. Script mode is used to create and edit python source file.


2.What is a literal? What are the types of literals?

Answer:

  • Literal is raw data given in a variable or constant.
  • In Python, there are various types of literals.
  1. Numeric
  2. String
  3. Boolean

3.Write short notes on Tokens?

Python breaks each logical line into a sequence of elementary lexical components known as Token.
The normal token types are

  1. Identifiers
  2. Keywords
  3. Operators
  4. Delimiters and
  5. Literals.

4.What are the different operators that can be used in Python?

5.Write short notes on Exponent data?

An Exponent data contains decimal digit part, decimal point, exponent part followed by one or more digits.
12.E04, 24.e04 # Exponent data



PART III

Short Answers:


1.What are the assignment Operators that can be used in Python?

  • In Python,= is a simple assignment operator to assign values to variables.
  • There are various compound operators in Python like +=, -=, *=, /=,%=, **= and / / = are also available.
  • Let = 5 and = 10 assigns the values 5 to and 10 these two assignment statements can also be given a =5 that assigns the values 5 and 10 on the right to the variables a and b respectively.
OperatorDescriptionExample
Assume x=10
=Assigns right side operands to left variable»> x=10»> b=”Computer”
+=Added and assign back the result to left operand i.e. x=30»> x+=20 # x=x+20
=Subtracted and assign back the result to left operand i.e. x=25>>> x-=5 # x=x-5

2.Write short note on Arithmetic operators with examples.

  • An arithmetic operator is a mathematical operator that takes two operands and performs a calculation on them.
  • They are used for simple arithmetic.
  • Most computer languages contain a set of such operators that can be used within equations to perform different types of sequential calculations.
  • Python supports the following Arithmetic operators.
Write short note on Arithmetic operators with examples

3.Write short notes on Escape Sequence with example?

  • In Python strings, the backslash “\” is a special character, also called the “escape” character.
  • It is used in representing certain whitespace characters: “t” is a tab, “\n\” is a new line, and “\r” is a carriage return.
  • For example to print the message “It’s raining”, the Python command is > > > print (“It \ ‘s raining”)
  • output:
    It’s raining
Write short notes on Escape Sequence with example

4.Explain Ternary Operators with examples.

Ternary operator is also known as a conditional operator that evaluates something based on a condition being true or false. It simply allows testing a condition in a single line replacing the multiline if-else making the code compact.
The Syntax conditional operator is,
Variable Name = [on – true] if [Test expression] else [on – false]
Example:
min = 50 if 49 < 50 else 70 # min = 50 min = 50 if 49 > 50 else 70 # min = 70


5.What are String Literals? Explain.

String Literals:
In Python, a string literal is a sequence of characters surrounded by quotes. Python supports single, double and triple quotes for a string. A character literal is a single character surrounded by single or double-quotes. The value with triple – the quote is used to give multi-line string literal.
Strings = “This is Python”
char = “C”
multiline _ str = “This is a multiline string with more than one line code”.



PART IV

Long Answers:

1.Discuss in detail about Tokens in Python?

Python breaks each logical line into a sequence of elementary lexical components known as Token.
The normal token types are

  1. Identifiers
  2. Keywords
  3. Operators
  4. Delimiters and
  5. Literals.

Identifiers:

  • An Identifier is a name used to identify a variable, function, class, module or object.
  • An identifier must start with an alphabet
    (A..Z or a..z) or underscore (_). Identifiers may contain digits (0 .. 9). „
  • Python identifiers are case sensitive i.e. uppercase and lowercase letters are distinct. Identifiers must not be a python keyword.
  • Python does not allow punctuation characters such as %,$, @, etc., within identifiers.

Keywords:
Keywords are special words used by Python interpreters to recognize the structure of the program. As these words have specific meanings for interpreters, they cannot be used for any other purpose.

Operators:

  • In computer programming languages operators are special symbols which represent computations, conditional matching, etc.
  • The value of an operator used is called operands.
  • Operators are categorized as Arithmetic, Relational, Logical, Assignment, etc. Value and variables when used with the operator are known as operands

Delimiters:
Python uses the symbols and symbol combinations as delimiters in expressions, lists, dictionaries, and strings
Following are the delimiters knew as operands.

()]{}
,:.;
  • Numeric
  • String
  • Boolean

Explain input() and print() functions with examples.

input () function:
In Python input() function is used to accept data as input at run time.
Syntax:
Variable = input (“prompt string”)

  • where, prompt string in the syntax is a statement or message to the user, to know what input can be given.
  • The input() takes whatever is typed from the keyboard and stores the entered data in the given variable.
  • If prompt string is not given in input() no message is displayed on the screen, thus, the user will not know what is to be typed as input

Example:
> > > city=input(“Enter Your City: “)
Enter Your City: Madurai
> > > print(“I am from “, city)
I am from Madurai

  • The input () accepts all data as string or characters but not as numbers.
  • If a numerical value is entered, the input values should be explicitly converted into numeric data type.
  • The int( ) function is used to convert string data as integer data explicitly.

Example:
x= int (input(“Enter Number 1: “))
y = int (input(“Enter Number 2: “))
print (“The sum =”, x+y)
Output
Enter Number 1: 34
Enter Number 2: 56
The sum = 90
print () function :
In Python, the print() function is used to display result on the screen. The syntax for print() is as follows:

Syntax:
print (“string to be displayed as output” )
print (variable)
print (“String to be displayed as output variable)
print (“String 1 “, variable, “String 2′”,variable, “String 3” )….)

Example
> > > print (“Welcome to Python Programming”)
Welcome to
Python Programming
> > > x= 5
> > > y= 6
> > > z=x+y
> > > print (z)
11
> > > print (“The sum =”,z)
The sum=11
> > > print (“The sum of”,x, “and “, y, “is “,z)
The sum of 5 and 6 is 11

  • The print( ) evaluates the expressions before printing it on the monitor
  • The print( ) displays an entire statement which specified within print ( )
  • Comma (,) is used as a separator in print more than one time

CHAPTER 6: CONTROL STRUCTURES

PART I

Multiple Choice Questions:

1.How many important control structures are there in python?


a) 3

b) 4

c) 5

d) 6

Answer: a) 3


2.Which statement is the simplest of all decision making statements?


a) if – else

b) if..elseif

c) simple if

d) Nested if

Answer :- c) simple if


3.Which punctuation should be used in the blank?
if__
statement-block 1
else:
statement-block 2


a) ;

b):

c) ::

d)

Answer :- b):


4.elif can be considered to be an abbreviation of ………….


a) elseif

b) if

c) simple if

d) None

Answer:- a) elseif


5.What plays a vital role in python programming?


a) statements

b) control

c) structure

d) indentation

Answer :- d) indentation


6.How many types of loops are there in python?


a) 2

b) 3

c) 4

d) 5

Answer :-


7.Which is the entry check loop?


a) for

b) while

c) a & b

d) None

Answer :- a) for


8.The condition in the if statement should be in the form of …………..


a) Arithmetic or Relational expression

b) Arithmetic or Logical expression

c) Relational or Logical expression

d) Arithmetic

Answer :- c) Relational or Logical expression


9.Which is the most comfortable loop?


a) do-while

b) while

c) for

d) if…elif

Answer :- c) for


10.A loop placed within another loop is called as ……………..?


a) for loop

b) while loop

c) Nested loop

d) do-while loop

Answer :- c) Nested loop


PART II

Very Short Answers:

1.Define Control Structures?

A program statement that causes a jump of control from one part of the program to another is called a control structure or control statement.


2.Write the syntax of if-else statement?

Syntax:
if:
statements – block 1
else:
statements – block 2


3.Write note on range() in loop?

Usually in Python, for loop uses the range() function in the sequence to specify the initial, final and increment values. range() generates a list of values starting from start till stop – 1.


4.Name the 3 jump statements in Python?

goto
continue
break

5.Write a note on break statement?

  • The break statement terminates the loop containing it.
  • Control of the program flows to the statement immediately after the body of the loop.
  • When the break statement is executed, the control flow of the program comes out of the loop and starts executing the segment of code after the loop structure.
  • If break statement is inside a nested loop (loop inside another loop), break will terminate the innermost loop.

PART III

Short Answers:

1.Write a note on if -else structure.

The if-else statement provides control to check the true block as well as the false block. Following is the syntax of ‘if-else’ statement.
Syntax:
if:
statements – block 1
else:
statements – block 2


2.Write the syntax of while loop.

The syntax of while loop in Python has the following syntax:
Syntax:
while:
statements block 1
[else:
statements block 2]


3.What is the output of the following code?
for i in range (2,10,2):
print (i, end =’ ‘)

What is the output of the following code?

4.Write the differences between branching and looping?


5.List the differences between break and continue statement.

BreakContinue
Break statement terminates the loop containing it and control reaches after the body of the loopContinue statement skips the remaining part of a loop and start with next iteration.

PART IV

Long Answers:

Write a detail note on for loop.

  • for loop is the most comfortable loop. It is also an entry check loop.
  • The condition is checked in the beginning and the body of the loop
    (statements-block 1) is executed if it is only True otherwise the loop is not executed.

Syntax:
for counter_variable in
sequence:
statements – block 1
[else: # optional block statements – block 2]

  • The counter, variable mentioned in the syntax is similar to the control variable that we used in the for loop of C++ and the sequence refers to the initial, final and increment value.
  • Usually in Python, for loop uses the range () function in the sequence to specify the initial, final and increment values, range () generates a list of values starting from start till stop-1.

The syntax of range() follows:
range (start, stop, [step])
Where,
start – refers to the initial value
stop – refers to the final value
step – refers to increment value,
this is optional part.

Examples for range():
range (1,30,1) – will start the range of values from 1 and end at 29 range (2,30,2) – will start the range of values from 2 and end at 28 range (30,3,-3) – will start the range of values from 30 and end at 6E range (20) – will consider this value 20 as the end value ( or upper limit) and starts the range count from 0 to 19 (remember always range () will work till stop -1 value only)

Example-Program:
#Program to illustrate the use of for loop – to print single digit even number
for i in range (2,10,2):
print (i, end=”)

What is the output of the following code?

Write a python program to display all 3 digit odd numbers.

Odd Number (3 digits)
for a in range (100, 1000)
if a % 2 = = 1:
print b
Output:
101, 103, 105, 107, .. …… 997, 999


CHAPTER 7: PYTHON FUNCTIONS

PART I

Multiple choice questions

1.A named blocks of code that are designed to do one specific job is called as ……………


a) Loop

b) Branching

a) Function

d) Block

Answer :- a) Function


2.Which function is called as anonymous unnamed function …………..?


a) Lambda

b) Recursion

c) Function

d) Define

Answer :- a) Lambda


3.A function which calls itself is called as ……………


a) Built-in

b) Recursion

c) Lambda

d) Return

Answer :- b) Recursion


4.Which of the following keyword is used to begin the function block?


a) define

b) for

c) finally

d) def

Answer :- d) def


5.While defining a function which of the following symbol is used?


a) ;

b) .

c) :

d) $

Answer :- c) :


6.Which of the following keyword is used to exit a function block?


a) define

b) return

c) finally

d) def

Answer :- b) return


7.………… function returns an absolute value of a number?


a) abs( )

b) ord( )

c) chr( )

d) bin( )

Answer :-


8.Python ……….. should not be used as function name ?


a) key words

b) arguments

c) variables

d) scope

Answer :-


9.A variable with …………..can be used anywhere in the program?


a) local scope

b) global scope

c) class scope

d) function scope

Answer :- b) global scope


10.Any number of return statements are allowed in a function definition but ……… of them is executed at run time?


a) only one

b) two

c) three

d) four

Answer :- a) only one


PART II

Very Short Answers:

1.What is function?

Functions are named blocks of code that are designed to do a specific job. If you need to perform that task multiple times throughout your program, you just call the function dedicated to handling that task.


2.Write the different types of function?

  1. User-defined functions
  2. Built-in functions
  3. Lambda functions
  4. Recursive functions

3.What are the advantages of function?

  • It avoids repetition and makes high degree of code reusing.
  • It provides better modularity for your application.

4.Write short notes about sqrt( ) function with example?

Function : sqrt ()
Description: Returns the square root of x (Note: x must be greater than zero) Syntax: sqrt (x)
Example:
a=49
b= 25
print (math.sqrt (a))
print (math.sqrt (b))
Output:
7.0
5.0


5.Write about return statement.

  1. The return statement causes your function to exit and returns a value to its caller. The point of functions in general is to take inputs and return something.
  2. The return statement is used when a function is ready to return a value to its caller. So, only one return statement is executed at run time even though the function contains multiple return statements.
  3. Any number of ‘return’ statements are allowed in a function definition but only one of them is executed at run time.

PART III

Short Answers:

1.Writ short note about anonymous functions?


2.Write the rules of the local variable.

  • A variable with a local scope can be accessed only within the function or block that it is created in.
  • When a variable is created inside the function/block, the variable becomes local to it.
  • A local variable only exists while the function is executing.
  • The format arguments are also local to function.

3.Write the basic rules for a global keyword in python

  • When we define a variable outside a function, it’s global by default. We don’t have to use the global keyword.
  • We use a global keyword to read and write a global variable inside a function.
  • Use of global keyword outside a function has no effect.

4.Differentiate ceil() and floor() function?

Cell()Floor ()
ceil () returns the smallest integer greater than or equal to the given value.floor() returns the largest integer less than or equal to the given value.

5.How recursive function works?

  • Recursive function is called by some external code.
  • If the base condition is met then the program gives meaningful output and exits.
  • Otherwise, the function does some required processing and then calls itself to continue recursion.

PART IV

Long Answers:


1.Explain the following built in functions.
id ( ), chr ( ), round ( ), type ( ), pow ( )



2.Explain recursive function with an example.

Python recursive functions
When a function calls itself is known as recursion. Recursion works like loop but sometimes it makes more sense to use recursion than loop. You can convert any loop to recursion.
A recursive function calls itself. Imagine a process would iterate indefinitely if not stopped by some condition! Such a process is known as infinite iteration. The condition that is applied in any recursive function is known as base condition. A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.

Working Principle:

  1. Recursive function is called by some external code.
  2. If the base condition is met then the program gives meaningful output and exits.
  3. Otherwise, function does some required processing and then calls itself to continue recursion. Here is an example of recursive function used to calculate factorial.

Example:
def fact (n):
if n = = 0:
return 1
else:
return n * fact (n – 1)
print (fact (0))
print (fact (5))
Output:
1
120

2 COMMENTS

Comments are closed.