CBSE COMPUTER SCIENCE
Ir al canal en Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
Mostrar más549
Suscriptores
Sin datos24 horas
Sin datos7 días
Sin datos30 días
Archivo de publicaciones
Python Fundamentals Practice Questions-5
Q1. Write the output of the following :
>>> x = 8
>>> x = 5
>>> print (x + x)
Ans. 10
Q2. Is the following statement correct?
>>> a, b, c = 2 , 3 , 'Amit'
Ans. yes
Q3. Identify the invalid variable names from the following and specify the reason also.
a) m_n
b) unit_day
c) 24Apple
d) #sum
e) for
f) s name
Ans. 24apple : Variable can not start with number
#sum : Variables can not start from special character.
for : Keyword can not be used as variable
s name : Spaces are not allowed in variable names
Q4. What are keywords?
Ans. Keywords are reserved words which have special meanings to python
Q5. Keywords can be used as variable names (T/F)
Ans. False
Q6. Write the code to display all the keywords available in python.
Ans.
import keyword
print(keyword.kwlist)
Q7. What do you mean by expression?
Ans. A combination of operators and operands is called expression.
like - a + b * c
Q8. Write the python expressions equivalent to the following algebraic/arithmetic expressions
z = u/5
z = 9ab + d
z = x+4/j + 7
Ans.
1. z = u/5
2. z = 9*a*b + d
3. z = x + 4/j + 7
Q9. What are operators? Name three types of operators.
Ans. Operators are special symbols that perform a specific task (arithmetic
or logical operations)
Three types of operators are
1. Logical Operators
2. Relational Operator
3. Mathematical Operator
Q10. >>> 7 % 10 will return ____________________
Ans 7
*******
Python Fundamentals Practice Questions-6
Q1. Write the output of the following:
1. print("hello * 5")
2. print("hello" * 5)
3. print("***" * 5)
4. print("Hello", "how", "R", "U")
5. print("Hello" + "how" + "R" + "U")
6. print("Amit" + "Sethi")
7. print(23 + 9)
8. print ("7 + 9")
9. print(7/6)
10. print(7//6)
11. print(8 % 2)
12. print(3 % 7)
13. print(4 3)
14. print (7 * 5)
15. print (8 - 16 )
Ans
1. hello * 5
2. hellohellohellohellohello
3. ***************
4. Hello how R U
5. HellohowRU
6. AmitSethi
7. 32
8. 7 + 9
9. 1.1666666666666667
10. 1
11. 0
12. 3
13. 64
14. 35
15. -8
Q2. What do you mean by string concatenation? Give example
Ans. String Concatenation means joining the strings. for example
>>>s = "Amit" + "Sethi"
>>> print(s)
Output is :
AmitSethi
Q3. What do you mean by binary and unary operators? Give one example of each.
Ans. Binary operators work on two or more operands like Division (+), Multiplication (*).
2 / 3
4 * 3
Unary operators work only on one operand like Subtraction (-)
-9
-7
Q4. Evaluate the following expressions
1. 23 + 4 **2
2. 9 * 3 - 8 + 6
3. 7%2 + 7//2
4. 67 + 3%3
5. 12 % 4 + 6 + 4 // 3
Ans
39
25
4
67
7
Q5. Write the name and purpose of the following operators.
1. //
2. %
3.
4. *
Ans.
1. Floor Division
2. Modulo Division
3. Power
4. Multiplication
*******
Q 5. What is the purpose of type() function?
Ans. This function tell us about the data type of a variable. for example
a = 10
print(type(a))
OUTPUT :
Q 6. Write the output of the following.
>>> type(10)
>>>type('10')
>>>type(10.0)
>>>type(True)
>>>type('False')
Ans.
Q 7. Which function is used to find the data type of variable?
Ans. type() function
Q 8. Write the output of the following
>>> a = "hello"
>>> b = 10
>>> c = 9.8
>>> d = 7 + 3.6j
>>> print(a)
>>> print(b)
>>> print(c)
>>> print(d)
Ans
hello
10
9.8
7 + 3.6j
Q9. Identify the variable name, variable type, value and operator used in the following statement.
>>> x = 9
Ans.
variable name -- x
variable type -- integer
value -- 9
operator -- =
Q 10. What do you mean by assignment operator?
Ans. An operator which is used to assign a value to a variable is called assignment operator. Symbol of assignment operator is '=', for example
c = 10, value 10 will be assigned to variable 'c'
*******
Python Fundamentals Practice Questions-1
Q. Name two modes of Python.
Ans. Interactive Mode and Script Mode
Q2. Write Full Form of IDLE
Ans. Integrated Development Learning Environment
Q3. Interface mode of python is also known as _______________.
Ans. Python Shell
Q4. In which mode we get result immediately after executing the command?
Ans. Interactive mode
Q5. Write the output of the following.
a. >>> x = 5
>>> y = 7
>>> print(x + y )
b. >>> print(2 **5)
Ans
a. 12
b. 32
Q6. Write one drawback of interactive mode.
Ans. We can not save our commands
Q7. Ananya purchased 5 pencils and 2 erasers at the cost of Rs 7 and Rs 5 respectively. Write the program to calculate & display the total amount paid by ananya.
Ans.
penc = 7
er = 5
totcost = penc * 5 + 2 * er
print("Total cost paid by Ananya is",totcost)
Q8. What do you mean by comments in Python?
Ans. Non executable lines are called Comments
Q9. Which symbols are used for single line comments and multiple line comments?
Ans. # symbol
Q10. What do you mean by variable?
Ans. Named storage location of value is called variable
*******
Python Fundamentals Practice Questions-2
Q1. What is the purpose of creating variables?
Ans. Variables are used to store values which we can use later in our programs.
Q2. Write code to find the address of variable.
Ans. id command is used to find the address of variable for example, to find the address of variable ‘x’ code is
>>>id(x)
Q3. What do you mean by data type?
Ans. Data type refers to the type of value used for example integer, float string etc
Q4. Write three numeric data type in python.
Ans. Integer, Floating Point and Complex
Q5. Name three sequential data types in python.
Ans. List, tuple and String
Q6. >>> x = 200
>>> y = 10.5
Write the data type of variable x and y.
Ans. a. Integer
b. Floating point
Q7. Data type of variable is according to the value it holds.(T/F)
Ans. True
Q8. Which data type store the combination of real and imaginary numbers?
Ans. Complex
Q9. Write the output of the following:
>>> 4.7e7
>>> 3.9e2
Ans.
47000000
390
Q10. Which data type return value True or False?
Ans. Boolean
*******
Python Fundamentals Practice Questions-3
Q1. Write the output of the following :
1. >>> (75 > 2 **5)
2. >>> (25 != 5 *2)
1. True
2. True
Q2. Which operator can be changed in above part (2) so that it returns True?
Ans. == in place of !=
Q3. Dictionary is enclosed in ___________ brackets.
Ans. Curly braces {}
Q4. What do you mean by keywords in python?
Ans. Keywords are reserved words. We can not use keywords for variable name or any other identifier.
Q5. Keywords can be used as variable names (T/F)
Ans. False
Q6. Write the code to display all keywords in python.
Ans import keyword print(keyword.kwlist)
Q7. Write two keywords which start with capital letters.
Ans. True, False
Q8. Write the output of the following
>>> str = "Informatics"
>>>str[3] = 'e'
>>> print(str)
Ans. Type Error
Q9. Write the output of the following:
>>> a = [1,2,3]
>>>a[0] = 6
>>>print(a)
Ans. [6, 2, 3]
Q10. Name three types of operators in python.
Ans. 1. Mathematical Operator 2. Comparison Operator 3. Logical Operator
*******
Python Fundamentals Practice Questions-4
Q 1. What do you mean by Escape sequence?
Ans The sequence of characters after backslash is called escape sequence.
Q 2. Write the output of the following
>>> x = 2 + 5j
>>> print(x.real, x.imag)
Ans. 2.0 5.0
Q 3. What is None data type?
Ans. This data type is used to define null value or no value.
for example
m = none, Now the variable 'm' is not pointing to any value, instead it is pointing to none.
Q 4. Write the output of the following
>>> v1 = 10
>>> v2 = None
>>> v1
>>> v2
>>>print(v2)
Ans.
10
None
def Del(book):
if(book==[ ]):
print("Queue is empty")
else:
print("Deleted book name :",book.pop(0))
Q3. Write a menu driven program using function Qadd( ), Qdel( ) and disp( ) to add, delete and display the record of book using queue as data structure in python. Record of book store the following details : Book name, Book Number and Book Price
book=[ ]
ch='y'
def Qadd(book):
bn=input("Enter book name")
bnum=int(input("Enter book number"))
bp=int(input("Enter book price"))
temp=[bn,bnum,bp]
book.append(temp)
def Qdel(book):
if(book==[ ]):
print("No Record")
else:
print("Deleted Record is :",book.pop(0))
def disp(book):
l=len(book)
print("Book Name\tBook Number\tBook Price")
for i in range(0,l):
print(book[i][0],"\t\t",book[i][1],"\t\t",book[i][2])
while(ch=='y' or ch=='Y'):
print("1. Add Record\n")
print("2. Delete Record\n")
print("3. Display Record\n")
print("4. Exit")
op=int(input("Enter the Choice"))
if(op==1):
Qadd(book)
elif(op==2):
Qdel(book)
elif(op==3):
disp(book)
elif(op==4):
break
ch=input("Do you want to enter more(Y/N)")
while(ch=='y' or ch=='Y'):
print("1. Add Record\n")
print("2. Delete Record\n")
print("3. Display Record\n")
print("4. Exit")
op=int(input("Enter the Choice"))
if(op==1):
push(host)
elif(op==2):
pop(host)
elif(op==3):
display(host)
elif(op==4):
break
ch=input("Do you want to enter more(Y/N)")
For more questions on Data Structure in Python Click Here
Queue :
A queue is a specialized data structure in which elements are added at one end called Rear and removed from other end called Front.
Operations on Queue :
A queue performs only two operations :
1. Insert : In this a new element is added at the end of list called Rear.
2. Delete : In this an element is to be deleted from one end called Front.
NOTE : Insertion and Deletion of elements takes place at different end. Addition at Rear and Deletion at Front
Queues in Daily Life :
We can see the formation of queues in our daily life like :
1. Outside the ATM
2. In Bank
3. Buying Ticket in Movie Hall
Working with Queue using List:
The implementation of queue using list is a simple process as there are inbuilt function which we used during working with queue. Basic operations that we should know are :
NOTE : Enqueue term means adding element in queue while Dequeue term means deleting element from queue
1. How to create an empty queue?
2. How to add elements to a queue?
3. How to delete / remove elements from the queue
4. How to traverse or displaying elements of queue?
5. How to check for empty queue?
1. Creating an empty queue : We can create an empty queue as similar to stack like :
Q = list( ) or Q = [ ]
2. Adding an element to queue : Elements can be added by using the function append( ) of list. This function automatically add the new element at the end of the queue. like –
Q.append(4) : This code will add element 4 at the end of the queue named “Q”
3. Deleting an element from Queue : pop( ) function is used to delete an element from the queue. Before deleting an element, it is to be checked that whether queue is empty or not. Code to delete an element is :
if (Q == [ ]:
print("Queue is Empty")
else :
print("Deleted element is :", Q.pop(0)) # index value "0" indicate the very first value of the queue
4. Displaying elements of the queue : Elements of the queue can be displayed as given below :
L = len(Q)
for i in range(0, L):
print(Q[i])
5. Checking an empty Queue : We use the following code to check whether the queue named “Q” is empty or not.
if(Q==[ ]):
print("Queue is Empty")
Data Structure in Python – Question Answer
Q1. What is the difference between Stack and Queue data structure in python?
Q2. In queue, addition and deletion of elements take place at different ends(T/F)
Q3. Which method of list is used to add element at the end ?
Q4. Write the code to display all elements of queue named "Aqueue".
Q5. Write a function addQ(num) to add numbers in a queue using list. (num is a list of numbers)
Q6. Write full form of FIFO.
Q7. Queue works on _______________(FIFO/LIFO) concept.
Q8. Write 2 applications of stack.
Q9. Which method of list is used to remove last element of the list?
Practical Implementation of queue using list
Q1. Write a function Aqueue(student) and Dqueue(student) to add a new student name and remove a student name from a list student, considering them to act as insert and delete operations of the queue Data Structure in Python.
student=[ ]
def Aqueue(student):
sn=input("Enter name of student")
student.append(sn)
def Dqueue(student):
if(student==[]):
print("Queue is empty")
else:
print("Deleted student name :",student.pop(0))
Q2. Write a function Add(book) and Del(book) to add a new book name and remove a book name from a list book, considering them to act as insert and delete operations of the queue Data Structure in Python.
book=[ ]
def Add(book):
bn=input("Enter name of book")
book.append(bn)
