Professional Documents
Culture Documents
QUESTIONS:
THEORY
1. What are Variables?
Answer:It is a container which is used to contain values in the program
It helps to generate a memory for the values
2. What is the use input( ) in Python?
Answer:To take input from the user whatever you enter as input, the input function
converts it into a string.
3. Difference between sep and end in Python?
Answer:The end parameter basically prints after all the output objects present in one
output statement heve been returned.
The sep parameter diffentiate between the objects.
4. What is the default type of input function?
Answer:Int
5. Write a simple code to format string values?
Answer:
a=5
b=10
print(‘the value of a is {} and value of b is {}.format(a,b))
output;
the value of a is 5 and value of b is 10
6. If a = 5; print(‘a’); What will be the output?
Answer:
Output=a
7. What are Identifiers?
Answer:
It is user defined names which is given to identify variables functions classes modules
or objectives
8. Whether an Identifier starts with number?
Answer:
Identifier name should not starts with numbers
9. What are Keywords and name some in Python?
Answer:
Keywords are the reserved words in python. It is used to perform some specified task.
We cannot use a keyword as a variable, function or class.
Ex: and,or,not,if,elif,true,false,def,break,assert,while
10. Name the Datatypes in Python?
Answer:
Number-int,float,complex numbers
String-slice operator, Concatenation +, Asterisk *
Boolean-True,False
11. What is the use of Slice Operators?
Answer:
The slice operator is used to specify how slice a sequence
It is a feature that enables accessing parts of sequence like strings and lists
12. What is Concatenation?
Answer:Joining strings together and-to-end to create a new string
13. Whether two Integer values can be Concatenated?
Answer:yes
14. Types of Operators?
Answer:Arithmetic, comparison ,logical, assignment, bitwise, identity, membership
operator
15. Difference between Comparison and Logical Operator?
Answer:Comparison operator is used to compare the input or output
Logical operator is used to check the conditions if it is true or false
16. Difference between Arithmetic and Assignment Operator?
Answer:Arithmetic operator is used to perform mathematical operator
Assignment operator is used to assign or modify the values
17. What is Type Conversion?
Answer:The process of converting the value of one data type to another datatype is
called type conversion.
18. Difference Between Implicit and Explicit Conversion?
Answer:Implicit conversion is used to convert the smaller datatype to higher datatype
Explicit conversion is used to convert the higher datetype to smaller datatype
19. Which Type Conversion is build-in in Python?
Answer:Explicit type onversion
20. Name some Types Conversions in Python?
Answer:Int(),float(),str(),ord(),hex(),oct(),complex()
21. What is Comment in Python?
Answer:Comment is reduces figuring time of the program
22. What is Statements in Python?
Answer:A statement is an instruction that the python interpreter can execute
23. What is Control Structure?
Answer:It gives continuous result in python
24. Types in Control Structures?
Answer:
• Decision making statement:if,elif,else
• Looping statement:for while
25. Difference between Decision Making and Looping Statements?
Answer:
decision the statement execute either one or not execute on the basis of the condition
provided.
in loop the statement execute several times until the condition would not get false
26. Difference between for and while Loop?
Answer:
For loop allows a programmer to execute a sequence of statements several times it
abbreviates the code which helps to manage loop variables
While loop allows programmer to repear a single statement or a group of statement
for the true condition
27. What is the use of range( ) function?
Answer:
Used to generates a sequence of numbers over time at its simplest it accepts an integer
and return a range object
28. Various Parameters in range( ) function?
Answer:
It has 3 parameters:
• The range(stop) takes one argument
• Range(start,stop) takes two arguments
• Range(start,stop,stop)takes three arguments
29. What is the default starting range in range( ) function?
Answer:
0(zero)
30. What is the default incrementation value in range( ) function?
Answer:
One
31. Difference between break, continue and pass?
• break
We can stop the loop before it has looped through all the elements.
• continue
We can stop the current iteration of the loop, and continue with the next
• pass
Used to pass the set of block and continue the next
answer:
listOne = [3, 6, 9, 12, 15, 18, 21]
listThird=listOne[0::2]+listTwo[1::2] print(listThird)
output:
[3, 9, 15, 21, 8, 16, 24]
2. Given an input list removes the element at index 4 and add it to the 2nd position and
also, at the end of the list?
a. List = [54, 44, 27, 79, 91, 41]
Answer:
OUTPUT:
[54, 44, 91, 27, 79, 41, 91]
3. Given a list iterate it and count the occurrence of each element and create a dictionary
to show the count of each element?
a. list = [11, 45, 8, 11, 23, 45, 23, 45, 89]
b. Printing count of each item {11: 2, 45: 3, 8: 1, 23: 2, 89: 1}
Answer:
List = [11, 45, 8, 11, 23, 45, 23, 45, 89] print("Original list ", List)
countDict = dict()
for val in List:
else:
countDict[val] = 1
4. Remove duplicate from a list and create a tuple and find the minimum and
maximum number?
a. sampleList = [87, 45, 41, 65, 94, 41, 99, 94]
answer:
sampleList = [87, 52, 44, 53, 54, 87, 52, 53] print("Main List: ", sampleList)
sampleList = list(set(sampleList)) print("modified list:",sampleList)
tuple = tuple(sampleList)
print("tuple ", tuple)
minimum=min(tuple) maximum=max(tuple)
print("Minimum number is: ",minimum) print("Maximum number is: ",maximum)
output:
Main List: [87, 52, 44, 53, 54, 87, 52, 53] modified list: [44, 52, 53, 54, 87]
tuple (44, 52, 53, 54, 87)
Minimum number is: 44
Maximum number is: 87
output:
(50, 40, 30, 20, 10)
output:
tuple1: (99, 88) tuple2: (11, 22)
7. Copy element 44 and 55 from the following tuple into a new tuple
a. tuple1 = (11, 22, 33, 44, 55, 66)
answer:
print(tuple1.count(50))
output: 2
11. Write a program to find the Last Array element in a given array?
i. array(‘i’,[24,55,67,88,92])
answer:
from array import*
vals=array(‘I’,[4,4,5,6,7])
print(vals[-1])
12. Write a program using Numpy and perform Math Operations in Python?
Answer:
From array import*
Ary1=array([10,0,30])
Ary2=array([2,4,6])
Add=ary1+ary2
Sub=ary1-ary2
Mul=ary1*ary2
Div=ary1/ary2
Print(ary1)
Print(ary2)
Print(add)
Print(sub)
Print(mul)
Print(div)
print(sum([8,2,3,0,7]))
output:
20
40
60
80
100
25. Write a function calculation() such that it can accept two variables and calculate the
addition and subtraction of it. And also it must return both addition and subtraction in
a single return call.
Answer:
def calculation(a,b):
sum = a+b
sub = a-b
return sum,sub
sum,sub=calculation(20,10)
print('addition:',sum)
print('substraction:',sub)
output:
addition: 30
substraction: 10
26. Create a function showEmployee() in such a way that it should accept employee
name, and it’s salary and display both, and if the salary is missing in function call it
should show it as 9000.
Answer:
def showEmployee(name,salary):
print("The employee name is {} and his/her salary {} ".format(name,salary))
showEmployee("john",9000)
output:
The employee name is john and his/her salary 9000
27. Write a recursive function to calculate the sum of numbers from 0 to 10.
Answer:
def recurSum(n):
if n <= 1:
return n
return n + recurSum(n - 1)
# Driver code
n = 10
print(recurSum(n))
output:
55
28. Assign a same name to two different function and call it through the different
parameters.
Answer:
def area(l, b):
return l * b
def area(r):
import math
return math.pi * r ** 2
print(area(3))
output:
28.274333882308138
30. Take 10 integers from keyboard using loop and print their average value on the
screen.
Answer:
sum=0
count = 1
while (count<=10):
x = int(input("Enter the %d number?"%(count)));
sum = sum + x;
count=count+1;
average = sum / 10;
print("Average using