Qusetion and Answers Python
Qusetion and Answers Python
Ans. The Operator * is used to replicate a list by a specific number of times. With * operator
one operand has to be list and other should be an integer otherwise it will give an error.
A= [ 1, 2, 3] [1,2,3,1,2,3,1,2,3]
B= A*3
Print(B)
Q.2 what are Iterations? Explain two different ways of using Iterations?
Ans. Repetitive execution of the same block of the code over and over are referred to as
Iterations. The two different ways of using Iterations are in Python are While loop and for loop.
For loop – It is used to repeat a set of instructions for a fixed number of times. It is called
definite loop.
For i in[1,2,3,4]: 1
print i 2
While loop – It is used to repeat a set of instructions as long as the condition is true.It means
number of
Q.3 What is Type Conversion ? Explain the types of type conversion with the help of example.
Ans. Type Conversion in Python refers to the direct conversion of object one data type to
another data type.
For Example – the conversion of an integer value into a floating value or its textual
representation as a string and vice versa.
x=10
# check type of x
1. Syntax error – It means writing a code following the rules of Python language. It occurs
when we violate the rules of Python.
Eg. a + b = c
Syntax error : cannot assign operator.
2. Logical Error – This type of error occurs when we give a wrong formula for the
calculation to be done. , write a wrong logic for the problem to be solved through the
code.
3. Runtime error - It occurs during the execution pof program like wrong input or output
errors , undefined object division by zero errors.
c = a/b
Ans. The pop() function removes the last element or the element based on the index given
remove()function removes the first occurrence of the specified element.
print (marks)
val=vowels.pop(2) ‘I’
print (val)
A nested if statement is an if-else statement with another if statement as if the body or else the
body.
If (condition ):
Statement 1
elif (condition):
Statement 2
elif( condition ):
Statement 3
…
Else: