0% found this document useful (0 votes)
45 views

Python Question and Answers

The document contains examples of python code for various tasks like time alarms, calculating costs, checking odd/even numbers, and more. It also provides the explanations for software process steps and examples of code to find reciprocal, check vowels/consonants, and calculate net salary.

Uploaded by

Krishna Pechetti
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Python Question and Answers

The document contains examples of python code for various tasks like time alarms, calculating costs, checking odd/even numbers, and more. It also provides the explanations for software process steps and examples of code to find reciprocal, check vowels/consonants, and calculate net salary.

Uploaded by

Krishna Pechetti
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 16

24/02/2023

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

wrong code)import math


o = 200000
d = 100000
f = 25000
l = 10000*6*0.05
w = 20000
k= o+d
u= f+w
print((k+l)-u)

crt code)#input from the system

O=int(input("enter the opbal"))


D=int(input("enter the deposit amount"))
ft=int(input("fund transfer"))
ln=int(input("enter loan repaid"))
lni=(ln*6/12*5/100)
wd=int(input ("enter withdrawl amount"))
cb=(O+D-ft-ln-lni-wd)
print("closing balance is cb",cb)
after run)

enter the opbal200000


enter the deposit amount100000
fund transfer25000
enter withdrawl amount20000
closing balance is cb
> cb
244750.0

4) i)srilatha a mathematician wants to find out a method to convert negative value


to positive value
ii) mahesh wants to implement sin, cos, and tan functions in python
iii) Meghana likes to findout the square root value of 36
iv) Kiran wants to factorial value of 5
v)Reshma and reeta are close friends reshma lives in door no 10 and reeta lives
in Dr no 20, They
went for an long. Suddenly there was a power cut as a result they missed their
ways. reshma is
to in retas house. reta is in reshmas house help them to get back to therir
original locations using python?
pyt code)

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

1) time alarm program


to count alarm count in seconds maximum 5 min 0 count down listed in reverse
way the syntax?

code ans) import time


for i in range(5,0,-1): ruff:- (5 is starting time, 0 is ending
time, -1 is step remove from 5 to 0 ie5,4,3,2,1,0)
print(i)
time.sleep(1)
print("Beep")

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/-

code ans)import math


ac=int(input("annual consumption="))
oc=int(input("manufacturing cost="))
cc=int(input("storing cost="))
a=math.sqrt(2*ac*oc/cc)
print(a)

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?

code ans)import random


i=random.randint(0,3)
if i==0:
print("go")
else:
print("don't go")

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)import random


s=input("enter the status of signal=") ruff:-(if we type s than
answer is stop
if(s=='r'): y than
answer is get ready
print("stop") gr than
answer is go)
if(s=='y'):
print("get ready")
if(s=='gr'):
print("go")
iii) Anitha and samitha are playing a chess game. help them to find out the coins
used in the
chess board using python?

code ans)

4) i)deepak chavla classifies as a number as strong when it is divided by minimum


even value does not
produce a remainder value it is considered to be weak number? help deepak in
coding this logic?
ii)Miss sruthi wants to detect the patterns for the calender tear her focus is
on even month of the year
and its nature on which she wants to plan certain things the no of days if
mpre signifance in her view point.
how will sruthi through a program code

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

11) what is the code for finding odd or number?

Ans code) n=int(input("Enter a number="))


if(n%2==0):
print("Even")
else:
print("Odd")

12) What is the code for finding the leap years?

ans code)year=int(input("enter the year="))


if(year%4==0):
print("leapyear")
elif(year%100!=0):
print("leap year")
elif(year%400==0):
print("leap year")
else:
print("Not a leap year")

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

1) Mr. Hiranandini is working as a corporate executive. His basics salary is Rs


20,000 Based on the following data
Calculate his net salary of
a) Dearness allowannce @15%of the basic
b) HRA@20%
c) Yearly bonus of Rs 24000
d) Provident fund 10% of gross
e) Employee state insurance 20%gross
f) income tax deductions @25% of gross
g) Net slab rate of morethan 40,000 belongs to category x else y
formula) gross salary = basic salary+da+hra+monthly 202020bonus

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

2) Jack and jill are playing an alphabetical game is interstedin tracing


alphabetical
constants while jill is tacing alphabet vowels, help jack and jill by
python program
code ans)
# pyhton program
ch=input("enter the letter")
if(ch=="a" or ch=="b" or ch=="c" or ch=="d"):
print("The given letter is a vowel")
else:
print("The given letter is consonant")

ans)enter the letterk


The given letter is consonant
or
enter the lettera
The given letter is a vowel

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,"")

run ans) Enter the reciprocal number10


the reciprocal of 10 is 0.1
4) Write a python program to convert foreign heat to celcius degrees
code run)#converiton of foreign to celsius
import math
C= int(input("enter the foreign heat number",))
celsius=(C*33.8)
print(celsius,"celsius")

run ans)enter the foreign heat number1


33.8 celsius

5) Write a python program to findout the case reciprocal of a string


6) Write a python program to convert the lower case letters into upper case
letters?

code run)# Case conversion


k=input("Enter the lower case=")
print("The upper case letter is ",k.upper())

Run ans)Enter the lower case=kittu krishna


The upper case letter is KITTU KRISHNA

7) Write the program to the swap case?

Code ans)# Swap case coding


s= input("The swap letter=")
print("The swap case letter is ",s.swapcase())

ru ans)The swap letter=KITTU


The swap case letter is kittu
OR
The swap letter= kittu KITTU
The swap case letter is KITTU kittu

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?

Code ans) # Swap case coding


s= input("Enter the string function = ")
print("The swap case letter is ",s.capitalize())

run ans) Enter the string function = kittu


The swap case letter is Kittu

ii) Write a string function to combine two strings to get the desired string?

code ans)# adding name by using sring function


img1="kittu "
img2="mechanical "
img3="engineer"
print(img1+img2+img3)

run code) kittu mechanical engineer

iii) Write a simple string function to apply swap case?

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

i) How to print the middle letters?

code ans)# Extrract coding


x="mechanical engineer" (ruff:- "mechanical engineer"
print(x[0],x[1],x[6]) --> "0123456789 .... "
print(x[-1],x[-10]) " .... -8-7-6-5-4-3-2-1")

run ans)m e i
r l

ii) how to replace the name by using python code?

code ans)#changing name at certain place


x="kittu the mechanical engineer"
print(x.find("kittu"))
print(x.replace("kittu","krishna"))

run ans)0
krishna the mechanical engineer

iii)
LIST

1) A list is a container data type that contains similar elements


2) items in a list are mutuable(changable)
3) The operations performed in a list are
a) finding out the minimum value
b) finding out the maximum value
c) length, sort, reverse, deleting the contest in the list and deleting the list

ExERCISE

i) create a list of 3 names

code ans) #creating names


Names=["kittu","mechanical","engineer"]
print(Names)

run ans) ['kittu', 'mechanical', 'engineer']

ii) insert a name kittu before mechanical engineer?


sfter
code ans)#inserting names
names=["mechanical","engineeer"]
print("before the insert code=",names)
names.insert(0,'kittu')
print("after the insert code=",names)

Run ans) before the insert code= ['mechanical', 'engineeer']


after the insert code= ['kittu', 'mechanical', 'engineeer']

iii) Remove a name he before mechanical engineer?

code ans) # Removing names


names=["he","mechanical","engineer"]
print("before removal=",names)
names.remove('he')
print("after the removal process=",names)

Run ans) before removal= ['he', 'mechanical', 'engineer']


after the removal process= ['mechanical', 'engineer']

iv)Reverse the names of mechanical engineer?

code ans) #Reverse the names


name=["mechancal",'engineer']
print("before reverse the name=",name)
name.reverse()
print("after reverse the name=", name)

Run ans) before reverse the name= ['mechancal', 'engineer']


after reverse the name= ['engineer', 'mechancal']

AFTERNOON
EXERCISES

i) In an intercollege competition there is a team A that contains odd number of


students.
team B consists of even number of students. The event co-ordinator mr.bhaskar wants
to
prepare the list of members in the both teams, using python help bhaskar to prepare
list?

Code ans)# list of members


B=input("Enter the odd number of students")
A=input("Enter the even number of students")
print(B+A)

Run ans)Enter the odd number of students1, 2, 3, 4, 5,


Enter the even number of students6, 7, 8, 9
1, 2, 3, 4, 5, 6, 7, 8, 9

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?

2) online shopping form:-

Customer id:
Customer name:
product name:
Rate :
Qty :
Value :
Payment :

Solution using python


i) Prepare a list of frequently purchased articles?

ii) Payment through cards gave a 5% discount?


iii)Findout the maximum value for frequently purchased product?
iv) findout the number of products purchased in a day?
v) Findout the average price for products purchased through cards?
vi) Add 2 customers ordering for a product today?
vii) Delete the product not frequently purchased?

# Online shopping form


import time
i=input("Enter the customer ID= ")
if(i=="21a35a0322"):
print("customer name: P.Krishna")
time.sleep(1)
if(i=="21a35a0322"):
print("Rate: 1,15000")
time.sleep(1)
if(i=="21a35a0322"):
print("Qty :1000")
time.sleep(1)
if(i=="21a35a0322"):
print("value: medium")
time.sleep(1)
if(i=="21a35a0322"):
print("Payment:Online")
time.sleep(1)
if(i=="21a35a0322"):
print("Product name: Pulsar 150")

01/03/2023
MORNING

Container data types in python:-

i) List--> it is an unordered collection of elements.


2)Each and every element is identified by its indexes.
3) List can have duplicate values.
4) The elements in the list are mutable by nature.
5) Each and every element in the list can be appended/deleted.
6) List can be heterogeneous.

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])

run ans)('this', 'is', 'tuple')


this is tuple
is
tuple

ii) Every tuple can identify by its unique name.


ii) Generally tuple can contain immmutable elements.
iv) Tuple cannot contain duplicate values.
v) Operations performed on the tuples.
vi) Tuples can be embedded in another tuple.
vii) Tuple generally represents row of data in a table.
viii) tuples can be made to perform CRUD operations.

tuple codes:-

i) How to find elements by using "in" in a python program?

code 1 ) #finding elements in a tuple using "in"


tup1=(12, 22, 23, 24, 25)
print(22 in tup1)
print(27 in tup1)

run ans) True .'. ruff ( bcz 22 number is available in tup1)


False .'. ruff ( bcz 27 number is not available in tup1)
ii) How to find the element which will be not in our parts by using "not in" code
in python

code 2 ) #finding elements in a tuple using "not in"


tup2=(12, 22, 23, 24, 25)
print(12 not in tup2)
print(27 not in tup2)

run ans ) False


True

iii) How to find the maximum and minimum values in a python?

code 3 )#finding the maximum, and minimum value in a tuple


tup3=(12, 22, 23, 24, 25)
#for max value code
print(max(tup3))
#for min value code
print(min(tup3))

run ans) 25 .'. ruff(it is max value in tup3)


12 .'. ruff(it is min value in tup3)

iv) how to place the values in a order format by using python?

code 4) #sorting data in a tuple


tup4=(5,6,3,4,9,2,1,8,7,0)
print(sorted(tup4))

run ans) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

v) How to add the values by using python code?

code 5)#finding the sum of elements in a tuple


tup5=(1,8,2)
print(sum(tup5))

run ans) 11 ruff (bcz 1+8+2=11)

vi) How to convert the rows into columns by using python?

code 6)# a program to obtain transpose of 3*4 matrix


k=[[1,2,3,4],[5,6,7,8],[9,0,3,4]]
u=zip(*k)
lst=list(u)
print(lst)

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)

vii) # Combine list integer and float tuples


integers=[10,20,30,40,50]
floats=(1.1,2.2,3.3,4.4,5.5)
ti=zip(integers,floats)
lst=list(ti)
for i,j in lst:
print(i,j)

code ans)# Combine list integer and float tuples


integers=[10,20,30,40,50]
floats=(1.1,2.2,3.3,4.4,5.5)
ti=zip(integers,floats)
lst=list(ti)
for i,j in lst:
print(i,j)

run ans)10 1.1


20 2.2
30 3.3
40 4.4
50 5.5

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

1) Find the name of the player who is not in a team?

code ans) # finding whether the person is in team or not.


A=('harish', 'devan','krishna','karthik','suresh','mahesh','munna')
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")

run ans)The name of the person is devan


He is in a team
(another run)
The name of the person is bujji
He is not in a team

2) Find the total score of runs of a team ?


code ans) #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)
print("Total score of the team is ",sum(h))

3) Sort the run rates of an individual players in the team


code ans)#sort the run rates
1==a
2==b
3==c
4==d
5==e
6==f
7==g
h=(a,b,c,d,e,f,g)
h=print(sorted(h))
4) Find out the maximum and minimum score of a player in a team

code ans)#find maximum and minimum score in all persons


#for maximum value
print(max(h))
#for minimum value
print(min(h)

5) Find out the details of odd number id of player


code ans)
6) Find out the total details of total runs of a player in a team
Details
7)The player details who plays belongs to south india only

OVERALL ANSWER FOR THE QUESTION AAAAA

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)]

You might also like