Revision Of The Basics Of Python Class 12 Computer Science Exam Questions

Exam Questions Class 12

Please refer to Computer Science For Revision Of The Basics Of Python Class 12 Computer Science Exam Questions provided below. These questions and answers for Class 12 Computer Science have been designed based on the past trend of questions and important topics in your class 12 Computer Science books. You should go through all Class 12 Computer Science Important Questions provided by our teachers which will help you to get more marks in upcoming exams.

Class 12 Computer Science Exam Questions Revision Of The Basics Of Python

Question. Data items having fixed value are called ………. .
(a) Identifiers
(b) functions
(c) Keywords
(d) literals 

Answer

D

Question. Escape sequences are treated as ………. .
(a) strings
(b) characters 
(c) integers
(d) none of these

Answer

B

Question. To store value in terms of key and value , what core data type does Python provide?
(a) List
(b) tuple
(c) class
(d) dictionary

Answer

D

Question. Suppose str=’welcome’ All the following expression produce the same result except one. Which one?
(a) str[ : : -6]
(b) str[ : : -1][ : : -6]
(c) str[ : :6]
(d) str[0] + str[-1]

Answer

A

Question. What is the output of the following code segment?
str1=”hello”
str2=”world”
print(str1+str2.upper())
(a) helloworld
(b) HELLOWORLD
(c) helloWORLD
(d) HELLO WORLD

Answer

C

Question. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?
(a) print(T[1])
(b) T[2] = -29
(c) print(max(T))
(d) print(len(T))

Answer

B

Question. Following set of commands is executed in Python shell ,what will be the output ?
>>>str=”welcome”
>>>str[:3]
(a) wel
(b) ome
(c) wce
(d) welcome

Answer

A

Question. To store in terms of key and value, what core data type does python provide?
(a) list
(b) tuple
(c) class
(d) dictionary

Answer

D

Question. Identify the valid declaration of L: L = [‘hello’, ’28.6’, ‘world’, ’13’]
(a) dictionary
(b) string
(c) tuple
(d) list

Answer

D

Question. What is the data type for the object L below in python?
L=1,4,’thanks’,34
(a) list
(b) dictionary
(c) tuple
(d) array

Answer

C

Question. Which of the following is wrong dictionary declaration?
(a) d= {“mon” : 1, “tue” : 2, “wed” : 3}
(b) d= {1 : “mon”, 2 : “tue”,3 : “wed”}
(c) d= {[1,2] : “hello”}
(d) d= {(1,2) : “hello”}

Answer

C

Question. Value 17.25 is equivalent to
(a) 0.1725E-2
(b) 0.1725E+2
(c) 1725E2
(d) 0.1725E2

Answer

B,D

Question. Which of the following is/are correct ways of creating strings ?
(a) name = Jiya
(b) name = ‘Jiya’ 
(c) name = “Jiya” 
(d) name = (Jiya)

Answer

B,C

Question. To convert the read value through input( ) into integer type, ……….( ) is used.
(a) floating
(b) float
(c) int
(d) integer

Answer

C

Question. Which of the following are valid identifiers ?
(a) my name
(b) _myname 
(c) myname 
(d) my-name

Answer

B,C

Question. Which of the following are literals ?
(a) myname
(b) “Radha”
(c) 24.5 
(d) 24A

Answer

B,C

Question. Select the reserved keyword in Python.
(a) else
(b) import
(c) print
(d) all of these 

Answer

D

Question. Special meaning words of Pythons, fixed for specific functionality are called ……….
(a) Identifiers
(d) functions
(c) Keywords
(d) literals

Answer

C

Question. Names given to different parts of a Python program are ………. .
(a) Identifiers
(b) functions
(c) Keywords
(d) literals

Answer

A

Very Short Answer Type Questions :

Question. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values are January, February and March respectively.
Answer: Month={1:’january’,2:’february’,3:’march’}

Question. A tuple is declared as T = (12,4,7,8,5) What will be the value of sum(T)
Answer: 36

Question. Write the output of the following code
T=(‘p’,’q’,’r’,’P’,’Q’)
print(max(T))
print(min(T))
Answer: r
P

Question. Name the built-in mathematical function / method that is used to return an absolute value of a number.
Answer: abs

Question. Write the output of the following code
T= (10,30,15,20,25)
print(max(T))
print(min(T))
Answer: 30
10

Question. Mention the output of the following Python function:
len([“hello”,2,4,6])
Answer: 4

Question. Name the key word used for defining a function
Answer: def

Question. If the following code is executed, what will be the output of the following code? name=”ComputerSciencewithPython” print(name[3:10])
Answer: puterSc

Question. Write the output of the following code
L=[‘cs’,’maths’,’phy’,’chem’,’eng’]
print(len(L))
Answer: 5

Question. Name the built-in mathematical function / method that is used to return min value in a list
Answer: min

Question. Name the built-in mathematical function / method that is used to round the numbers
Answer: round

Question. Name the built-in mathematical function / method that is used to return maximum value in a list
Answer: max

Question. Given the lists L=[10,30,16,8,50,17,12,42] , write the output of print(L[2:5])
Answer: [16, 8, 50]

Short Answer Type Questions :

Question. Deferentiate between parameters and arguments in Python. Mention a suitable example
Answer: A parameter is the variable listed inside the parentheses in the function definition. An argument is the value that are sent to the function when it is called.
def calc_sum(a,b):
return a+b
sum_val=calc_sum(2,3)
print(sum_val)

Question. Mention the output:
def print_hello():
print(“Hello”)
print_hello()
print_hello()
Answer: Here calc_sum(a,b) -> a and b are parameters
calc_sum(2,3) -> 2 and 3 are arguments
Hello
Hello

Question. Differentiate between Global and Local variable with a suitable example
Answer: Local variables can be accessed only inside the function in which they are declared, whereas global variables can be accessed throughout the program body by all functions
x=10
def local_chk():
y=5
Here x is global variable and y is local variable.

Question. Write a function check_pos_neg(num) which takes a number from the user and prints whether the number is Zero or positive or negative
Answer: def check_pos_neg(num):
if num==0:
print(“The number is Zero”)
elif num <0:
print(“The number is Negative”)
else:
print(“The number is Positive”)
num=int(input(“Enter a number:”))
check_pos_neg(num)

Question. Differentiate between Positional Argument and Default Argument of function in python with suitable example
Answer: Positional arguments are arguments that can be called by their position in the function definition.
Python allows function arguments to have default values; if the function is called without the argument, the argument gets its default value.
def function(a, b, c):
print(a,b,c)
A positional argument is passed to the function in this way.
function(1,2,3)
will print
1 2 3
def function(a, b, c=3):
print(a,b,c)
function(1,2)
will print
1 2 3

Question. Write a function compute_len(strinp) which takes a string and returns the length of the string
Answer: def compute_len(strinp):
return len(strinp)
str_a=input(“Enter the String:”)
compute_len(str_a)

Question. Write a function comp_sum(lista) which takes a list of integers and return the sum
Answer: def comp_sum(lista):
total=0
for i in lista:
total+=i
return total
listinp=eval(input(“Enter list:”))
print(comp_sum(listinp))

Question. What is the meaning of return value of a function? Give an example to illustrate its meaning.
Answer: The Python return statement is a special statement that you can use inside a function or method to send the function’s result back to the caller. A return statement consists of the return keyword followed by an optional return value.
def calc_sum(a,b):
return a+b
sum_val=calc_sum(2,3)
print(sum_val)
This program will print: 5

Question. Write a function even_odd(num) which takes a number and checks whether the number is even or odd
Answer: def even_odd(num):
if num%2==0:
print(“Number is even”)
else:
print(“Number is odd”)
num=int(input(“Enter the Number:”))
even_odd(num)

Question. What are tokens in Python ? How many types of tokens are allowed in Python ? Examplify your answer.
Answer: The smallest individual unit in a program is known as a Token. Python has following tokens:
1. Keywords — Examples are import, for, in, while, etc.
2. Identifiers — Examples are MyFile, _DS, DATE_9_7_77, etc.
3. Literals — Examples are “abc”, 5, 28.5, etc.
4. Operators — Examples are +, -, >, or, etc.
5. Punctuators — ‘ ” # () etc.

Question. Which of these is not a legal numeric type in Python ? (a) int (b) float (c) decimal.
Answer: decimal is not a legal numeric type in Python.

Question. Find the errors in following code fragment :
c = input( “Enter your class” )
print (“Last year you were in class”) c – 1
Answer:
There are two errors in this code fragment:
1. c – 1 is outside the parenthesis of print function. It should be specified as one of the arguments of print function.
2. c is a string as input function returns a string. With c – 1, we are trying to subtract a integer from a string which is an invalid operation in Python.
The corrected program is like this:
c = int(input( “Enter your class” ))
print (“Last year you were in class”, c – 1)

Question. What are operators ? What is their function ? Give examples of some unary and binary operators.
Answer: Operators are tokens that trigger some computation/action when applied to variables and other objects in an expression. Unary plus (+), Unary minus (-), Bitwise complement (~), Logical negation (not) are a few examples of unary operators. Examples of binary operators are Addition (+), Subtraction (-), Multiplication (*), Division (/).

Question. Predict the output
Answer: a, b, c = 10, 20, 30 p, q, r = c – 5, a + 3, b – 4 print (‘a, b, c :’, a, b, c, end = ”) print (‘p, q, r :’, p, q, r) Output a, b, c : 10 20 30p, q, r : 25 13 16

Question. How will you convert a string to all lowercase?
Answer: To convert a string to lowercase, lower() function can be used. Example: 1 2 stg=’ABCD’ print(stg.lower()) Output: abcd

Question. What do you understand by undefined variable in Python ?
Answer: In Python, a variable is not created until some value is assigned to it. A variable is created when a value is assigned to it for the first time. If we try to use a variable before assigning a value to it then it will result in an undefined variable. For example: print(x) #This statement will cause an error for undefined variable x x = 20 print(x) The first line of the above code snippet will cause an undefined variable error as we are trying to use x before assigning a value to it.

Question. Write a program that displays a joke. But display the punchline only when the user presses enter key.
Answer: (Hint. You may use input( )) print(“Why is 6 afraid of 7?”) input(“Press Enter”) print(“Because 7 8(ate) 9 :-)”)

Question. Can nongraphic characters be used in Python ? How ? Give examples to support your answer.
Answer: Yes, nongraphic characters can be used in Python with the help of escape sequences. For example, backspace is represented as \b, tab is represented as \t, carriage return is represented as \r.

Question. What is the error in following code : X, Y = 7 ?
Answer: The error in the above code is that we have mentioned two variables X, Y as Lvalues but only give a single numeric literal 7 as the Rvalue. We need to specify one more value like this to correct the error: X, Y = 7, 8

Question. What are negative indexes and why are they used?
Answer: The sequences in Python are indexed and it consists of the positive as well as negative numbers. The numbers that are positive uses ‘0’ that is uses as first index and ‘1’ as the second index and the process goes on like that. The index for the negative number starts from ‘-1’ that represents the last index in the sequence and ‘-2’ as the penultimate index and the sequence carries forward like the positive number. The negative index is used to remove any new-line spaces from the string and allow the string to except the last character that is given as S[:-1]. The negative index is also used to show the index to represent the string in correct order.