All Tech at one spot
Section – A
1. What are comments? Give the symbol used for defining a Single line comment
Ans :- Comment are the additional readable information to clarify the source code.
Comment in Python begin with symbol # and generally end with end of the physical line.Comments
are not executed by interpreter.. They are used primarily to document the meaning and purpose of source code.
2.Which one is an invalid string ‘Python” or ’’’Python’’’?
Ans :- ‘Pyhton” is invalid because here we have one single quote and on the next side we have double quote.
3.Who developed python programming language?
Ans :- Guido Van Rossum in 1990s developed Python programming language.
4.Assign a string “CBSE School” into a variable NAME?
Ans :- NAME = “CBSE School”
5.Name two Boolean literals in Python.
Ans :- There are only two Boolean literals in Python. They are true and false.
6.Reema is confused between 3*2 and 3**3. Help her to know the difference between the two expressions.
Ans :- 3*2 is set for (*) multiplication operator. So here we can perform multiplication.
3**3 is set for (**)Exponent operator.So here we perform exponent
7.Which escape sequences represent the newline character?
Ans :- escape sequences represent the newline is \n.
8.Evaluate the expression given below if A= 16 and B = 15.
A % B // A
Ans :- 0
9.Write the following real constant into fractional form. 0.13E-4
Ans :-
10.Convert the Equivalent Expression for math.pow(6,3).
Ans :- import math
math.pow(6,3)
Output
216.0
11.Name Two Mutable Data Types in Python.
Ans :- The two Mutable Data Type in List,Dicitionary and Set.
12.Which looping statement is based on Condition.
Ans :- While Loop is based on Condition.
13.ALU Stands for ________.
Ans :- Arithmetic Logical Operator.
14.Name the function which is used to find the size of the string.
Ans :- Len function is used to find the size of the string.
15.Name the fastest Memory.
Ans :- Cache memory.
Section – B
1. Consider the Below String and Give the Ouput for below Questions
S = “Mera Desh Mahan”
>>> S[-5]
‘M’
>>> S[:6]
‘Mera D’
>>> S[1::2]
‘eaDs aa’
>>> S[::-1]
‘nahaM hseD areM’
2.Consider the Below Looping Statement and Give the Answers.
i=2
while i<9:
i=i+2
print(i)
Output :-
a. How Many times the loop run.
Sol:-
4
b. Give the Output.
Sol :-
4
6
8
10
c. What is the Value of i after the loop gets over?
Sol :-
10
d. Which is the Conditional Part in this Loop.
Sol :-
while i<9:
part – B
1.Difference Between Interpreter and Compiler.
Sol :-
A compiler is a computer program that reads a program written in a high-level language such as FORTRAN, PL/I, COBOL, etc
It can translate it into the same program in a low-level language including machine language
It consumes less time i.e., it is faster than an interpreter.
An interpreter is a program that executes the programming code directly instead of just translating it into another format.
It translates and executes programming language statements one by one
It consumes much more time than the compiler i.e., it is slower than the compiler.
2.What is cache memory? How it is Useful.
Ans:-
RAM is faster than secondary storage, but not as fast as a computer processor.The cache memory is a high speed memory available inside CPU access to data and instructions stored in RAM Memeory. It stores
the copies of the data from frequently accessed primary
memory locations, thus, reducing the average time
required to access data from primary memory
3.Difference Between Interactive and Script Mode in Python.
Ans :-
In interactive mode, instructions are given in front of Python prompt (eg. >>> or In[]prompts) in Python Shell. Python carries out the given instruction and shows the result there itself. In script mode, Python instructions are stored in a file generally with .py extension and are executed together in one go as a unit. The saved instructions are known as Python script or Python program.
4.What is difference between = = and =?
Ans :- In Python a single equal mark is used to assign a value to a variable, whereas two consecutive equal marks is used to check whether 2 expressions give the same value .
= is an assignment operator
== is an equality operator
5.Write any four features of Python language
Ans :-
Easy to Code. Python is a very high-level programming language, yet it is effortless to learn. …
Easy to Read. Python code looks like simple English words. …
Free and Open-Source. …
Robust Standard Library. …
Interpreted. …
Portable. …
Object-Oriented and Procedure-Oriented.
6.Write the output of following statements:
print (“I love ”, end = “ ”)
print (“Informatics Practices”)
Ans :-
7.What is a keyword in Python language? Give two examples of Python keywords
Ans :- Keyword is a special word that has a special meaning and purpose. Keywords are reserved and are a few. For example, if, elif, else etc. are keywords.
8.Write a python program to ask two string and merge that both string in third variable.
Ans :-
a =”Hardik”
b=”Kabra”
c=a+b
print(c)
9.Write any 4 rules for naming an identifier(variable).
Ans :-
• The name should begin with an uppercase or a
lowercase alphabet or an underscore sign (_).
• It can be of any length
It should not be a keyword or reserved word.
We cannot use special symbols like !, @, #, $, %, etc.
in identifiers.
Section – B
1.What is meant by “nested loop”? Write an example.
A nested loop is a loop inside the body of the outer loop. The inner or outer loop can be any type, such as a while loop or for loop.
A nested loop is a loop inside a loop.
The “inner loop” will be executed one time for each iteration of the “outer loop”:
Python programming language allows to use one loop inside another loop.
Syntax:-
for iterating_var in sequence:
for iterating_var in sequence:
statements(s)
statements(s)
Example:-
adj = [“red”, “big”, “tasty”]
fruits = [“apple”, “banana”, “cherry”]
for x in adj:
for y in fruits:
print(x, y)
2.What is meant by “nested if”? Write an example.
Ans :-
The nested if Statement Sometimes above discussed forms of if are not enough. You may need to test additional
conditions. For such situations, Python also supports nested-if form of if A nested if is an if that has another if in its if’s body or in elif’s body or in its else’s body.
In a nested if statement, either there can be if statement(s) in its body-of-if or in its body-of-elif or in its body-of-else or in any two of these or in all of these.
Syntax :-
if (conditional expression>:
statement
if <conditional expression> : if cconditional expression>:
statement(s)
else:
statement(s)
Example :-
3. Write a Program which ask a Sentence from User and then ask a Word Check that Whether that Word is Present in that Sentence or Not.
Sol :-
name = “Welcome to Python”
check= “to” in name
print(check)
4.Find error(s) in the following codes and rewrite the corrected codes and underline each
correction.
x = 5
i = = 1
while (i < = x) :
i =+ 2
print(Output is, “i”)
Sol :-
x = 5
i = 1
while (i <= x) :
i =+ 2
print(“Output is”,i)
1. Write a program to perform arithmetic operations like addition, subtraction , multiplication and division on |two numbers
Sol :-
no1 = int(input(“Enter the First number :- “))
no2 = int(input(“Enter the Second number :- “))
add = no1 + no2
sub = no1 – no2
mul = no1 * no2
div = no1 // no2
mod = no1 % no2
print(“The Sum of 2 number is :- “,add)
print(“The Sub of 2 number is :- “,sub)
print(“The mul of 2 number is :- “,mul)
print(“The div of 2 number is :- “,div)
print(“The mod of 2 number is :- “,mod)
2.Write a program to generate the series 1,4,9,16,25…
Sol :-
for i in range(1,6):
print(i*i,end=” “)
print(“\n”)