Python Question and Answers
Python Question and Answers
Afternoon class.
Mr.Amar is a plumber who repairs tanks. One of his client has a small hole in their
spherical tank.
water comes out of the hole as a result the tanks is half empty.
Amar fixes the hole and wants to find out the maximum capacity the tank can bold.
Help in with the python code.
The radius is 21cm why double is better than float?
Double offers more precision ie decimal points are accurate
3) Ram and raheem went for a walk on a cricket ground. The ground spans across 36cm
and there was a complete bush ie 10cm wide.
The corporation wants to assess the distance for laying affence around the
ground. Help them
with the python code if the cost of fencing is 2/cm.
total cost = 2(2L+2B)
ans:-import math
l=36
B=10
c= 2*(l+B)
print(c)
4) Krishnavamsi wants to automate his bankk details from the following particulars
a)opening balance =200000
b)deposit =100000
c)fund transfer =25000
d)loan repaid =10000 @6months@5%
e) withdrawl = 20000
f) Calculate his Cb
i)print(abs(-12))
ii)import math
a= math.sin(30)
print(a)
OR
import math
angle=int(input("enter the angle"))
print(math.sin(angle))
iii)import math
a=math.sqrt(int(input("enter square root value=")))
print(a)
iv)import math
a= math. factorial(int(input("enter the square root value=")))
print(a)
v)
25/02/2023
MORNING
2) Vaccine point is a company that produces vaccine for general public through out
the year.
The company wants to access the minimum number of doses tobe produced in a year.
from the
following data write a python program to do the calculation a annual consmption is
equal to
20000 units.
The cost of manufacturing a vaccine is Rs 20/-
The cost of storing the vaccine rs 10/-
3) i) Mr manish wants to check the status of a circuit using a python program help
him to findout
whether the circuit is in on or off state?
ii) Arun and tarun observe a traffic signal on the road. Develop a pyhton
program to show
the status of the traffic signal?
code ans)
FORENOON
5) an example for unary operator_________________
ans)++ or --
6) Python uses a set of_____________________ to implement some functionalities
ans)modules
3)Every python file is stored in the form of________________________
ans).py extension
4) Python proramming is top down approach
ans) False
(True or False)
5) comments in a python program is represented by_______________________
ans)#
6) _______________ is a unique spacing feature in python.
ans)indentation
7) Data can be contactenated in python using______________
ans)+
8) A divmod operator is represented by____________________________
ans)//
9) A ____________ is used to create wide spaces in python.
ans)split
10) Python is case sensitive (true or false)
ans)true
13)misses vasu enco is a share trading company and does analysis in python on
following data
Name of the share 2001-2002 2002-2003 2003-2004 2004-2005
X 40 24 18 27
Y 33 15 21 36
Z 57 32 61 88
i) Findout the maximum price of X share ?
ii) Findout the minimum price of Z share?
iii) Findout the Average price of Y share?
iv) Findout the percentage of increase of Z share in 2003-2004 compared to
previous year?
v) findout the rate of decrease in 20004-2005 compared to first year of issue
of x share?
ans code) i)
27/02/2023
MORINING
Software process:
1) Analysis : Understsanding the input components, processing logic, output
elements
2) Design : Logical design and physical design
Logical design means it focuses on how the data is represented
Physical design means it focuses on where the data is stored
3) Coding
4) Testing
5) Implementation
6) Maintenance
AFTERNOON
code Ans)
import math
Da= int(input("dearness allowance="))
da=(Da*0.15)
Hra= int(input("percent of Hra="))
hra=(Hra*0.2)
bonus= int(input("yearly bonus="))
salary= int(input("basic salary="))
monthly=(bonus/12)
GS=(salary+da+hra+monthly)
pf=(GS*0.1)
PF=pf
esi=(GS*0.2)
Esi=esi
IT=(GS*0.25)
it=IT
D=(pf+Esi+it)
k=(GS-D)
print(k)
ans) dearness allonce=20000
percent of Hra=20000
yearly bonus=24000
basic salary=20000
13050.0
answer is 13050
3) Write a python program to find out the reciprocal of a given number code:
code ans) #Reciprocal of a given number
r= int(input("Enter the reciprocal number"))
print("the reciprocal of ",r," is ",1/r,"")
28/02/2023
MORNING
String
1) string is a collection of relative character in a array.
2) There are many functions in strings such as upper lower find replace etc..,
3) Every string function is in the form of character array.
Exercises:
i) Write a function to convert the first letter of the string into capital letter?
ii) Write a string function to combine two strings to get the desired string?
TEXT SLICING
1)It is the process of viewing a portion of the text
2)Each and every text slicing will be index based
3)The first position will be represented by zero, and the last position will be
represented by -1
Exercises
run ans)m e i
r l
run ans)0
krishna the mechanical engineer
iii)
LIST
ExERCISE
AFTERNOON
EXERCISES
ii) mr.uday kiran wants to delete all the items from the list help him using python
?
iii) Sandhya wants to delete entire list help sandhya using pyhton code?
Customer id:
Customer name:
product name:
Rate :
Qty :
Value :
Payment :
01/03/2023
MORNING
Tuples:-
i) tuples can contain heterogeneous data.
code ans)k=('this','is','tuple')
print(k)
#slicing of tuple
print(k[0],k[1],k[2])
print(k[1])
print(k[2])
tuple codes:-
run ans)[(1, 5, 9), (2, 6, 0), (3, 7, 3), (4, 8, 4)] ruff(zip can convert rows
into columns
and columns into
rows)
Ecercise:
question AAAAA)
M/s and co is preparing a document on review of a match from the following details
player id, player name, series name, runs scored, run rate, average runs scored,
age, place
Generate output using tuples in python
Code ans)
import time
# finding whether the person is in team or not.
A=('harish', 'devan','krishna','karthik','suresh','mahesh','munna')
X=('Delhi','Russia','Bharat','Bombay','Ukraine','India','Bangladesh')
B=str(input("The name of the person is "))
C=B in A
if C==False:
print("He is not in a team")
else:
print("He is in a team")
#Total score of runs of a team
a=int(input("1st person score is "))
b=int(input("2nd person score is "))
c=int(input("3rd person score is "))
d=int(input("4th person score is "))
e=int(input("6th person score is "))
f=int(input("7th person score is "))
g=int(input("8th person score is "))
h=(a,b,c,d,e,f,g)
#sort the run rates
1==a
2==b
3==c
4==d
5==e
6==f
7==g
j=print(sorted(h))
#find maximum and minimum score in all persons
#for maximum value
full=print(max(h))
#for minimum value
print(min(h))
#details of odd number id player
i=str(input("The name of the person is "))
if(i=="harish"):
print("player name:Harish")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",a)
time.sleep(1)
print("run rate",a)
time.sleep(1)
if(i=="devan"):
print("player name:Devan")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",b)
time.sleep(1)
print("run rate",b)
if(i=="karthik"):
print("player name:Karthik")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",c)
time.sleep(1)
print("run rate",c)
time.sleep(1)
if(i=="suresh"):
print("player name:Suresh")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",d)
time.sleep(1)
print("run rate",d)
time.sleep(1)
if(i=="krishna"):
print("player name:Krishna")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",e)
time.sleep(1)
print("run rate",e)
time.sleep(1)
if(i=="mahesh"):
print("player name:Mahesh")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",f)
time.sleep(1)
print("run rate",f)
time.sleep(1)
if(i=="munna"):
print("player name:Munna")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",g)
time.sleep(1)
print("run rate",g)
time.sleep(1)
else:
print()
#Total details of total runs player
ti=(A,X)
lst=list(ti)
print(lst)
#Details of total runs of a player
if(full=="a"):
print("player name:Harish")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",a)
time.sleep(1)
print("run rate",a)
time.sleep(1)
if(full=="b"):
print("player name:Devan")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",b)
time.sleep(1)
print("run rate",b)
if(full=="c"):
print("player name:Karthik")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",c)
time.sleep(1)
print("run rate",c)
time.sleep(1)
if(full=="d"):
print("player name:Suresh")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",d)
time.sleep(1)
print("run rate",d)
time.sleep(1)
if(full=="e"):
print("player name:Krishna")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",e)
time.sleep(1)
print("run rate",e)
time.sleep(1)
if(full=="f"):
print("player name:Mahesh")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",f)
time.sleep(1)
print("run rate",f)
time.sleep(1)
if(full=="g"):
print("player name:Munna")
time.sleep(1)
print("series name:1")
time.sleep(1)
print("runs scored:",g)
time.sleep(1)
print("run rate",g)
time.sleep(1)
else:
print()
#Details who plays belongs to south india
print(A[3],X[3],c)
#Details of all the players
si=(A,X,h)
ui=zip(*si)
ki=list(ui)
print(ki)
Run ans)
The name of the person is krishna
He is in a team
1st person score is 30
2nd person score is 20
3rd person score is 13
4th person score is 110
6th person score is 8
7th person score is 10
8th person score is 22
[8, 10, 13, 20, 22, 30, 110]
110
8
The name of the person is munna
player name:Munna
series name:1
runs scored: 22
run rate 22
[('harish', 'devan', 'krishna', 'karthik', 'suresh', 'mahesh', 'munna'), ('Delhi',
'Russia', 'Bharat', 'Bombay', 'Ukraine', 'India', 'Bangladesh')]
karthik Bombay 13
[('harish', 'Delhi', 30), ('devan', 'Russia', 20), ('krishna', 'Bharat', 13),
('karthik', 'Bombay', 110), ('suresh', 'Ukraine', 8), ('mahesh', 'India', 10),
('munna', 'Bangladesh', 22)]