Python Practical
Python Practical
Input/Output
enter your rollno1001
Enter your NameAs
Enter Your CourseBCA
Enter your SectionBCA21&22
********************Student Details***********************
Student Roll No= 1001Student Name= AsCourse Name= BCASection= BCA21&22
************************************************************
Input/Output
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Enter first number13
Enter second number7
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
$$$$$$$$$$$ Basic Calculator$$$$$$$$$$$$$$
Sum of two no.= 20
Difference of two no.= 6
Product of two no.= 91
Floating Quotient of two no.= 1.8571428571428572
Integer Quotient of two no.= 1
Modulus of two no.= 6
Exponent of a^b= 62748517
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Input/Output
Enter First No.5
Enter Second No.7
Enter Third No.4
False
True
False
True
False
True
False
True
True
input/output
Enter first side of scalene triangle10
Enter second side of scalene triangle12
Enter third side of scalene triangle15
Area of scalene triangle= 59.81168364124187
input/output
Enter base of right angle triangle15
Enter height of right angle tringle20
Hypoteneous= 25.0
input/output
Enter radius of sphere15
Surface Area= 2827.4333882308138 Volume= 14137.166941154068
output: true
input/output
Enter the first number: 15
Enter the second number: 25
Enter the third number: 20
The largest number is: 25.0
The smallest number is: 15.0
➢ # program to read five subject marks (Physics, Chemistry,
Math, Computer and English) obtained by a class 12th student
and print report card of student
name=input("Enter Your Name")
rollno=int(input("Enter your Roll No."))
m1=int(input("Enter Marks obtained in Physics"))
m2=int(input("Enter Marks obtained in Chemistry"))
m3=int(input("Enter Marks obtained in Math"))
m4=int(input("Enter Marks obtained in Computer"))
m5=int(input("Enter Marks obtained in English"))
sum=m1+m2+m3+m4+m5
per=sum/5
print("ISC Result-2024*")
print("Roll No=",rollno, "Student Name=",name)
print("Statements of Marks*")
print("Physics=",m1,"Chemistry=",m2,"Mathematics=",m3)
print("Computer=",m4,"English=",m5)
print("")
print("Total Marks Obtained=",sum,"/500")
print("Percentage Marks Obtained=",per,"%")
print("")
print("Result is ")
if(per>=90 and per<=100):
print("Division=Distinction")
elif(per>=60 and per<90):
print("Division=First")
elif(per>=45 and per<60):
print("Division=Second")
elif(per>=33 and per<45):
print("Division=Third")
else:
print("Sorry, You are not pass")
print("")
input/output
Enter Your NameAs
Enter your Roll No.10101
Enter Marks obtained in Physics88
Enter Marks obtained in Chemistry80
Enter Marks obtained in Math93
Enter Marks obtained in Computer96
Enter Marks obtained in English79
****************ISC Result-2024*******************
Roll No= 10101 Student Name= As
**Statements of Marks*****************************
Physics= 88 Chemistry= 80 Mathematics= 93
Computer= 96 English= 79
****************************************************
Total Marks Obtained= 436 /500
Percentage Marks Obtained= 87.2 %
****************************************************
Result is
Division=First
****************************************************
➢ Write a program to read monthly income of an employee and
calculate annual income. also calculate income tax based on
following conditions:
for income up to 500000 tax=0
for next 5 lakh tax=10%
for next 10 lakh tax=20%
for rest tax=30%
name=input("enter your name")
mi=float(input("enter monthly Salary"))
ai=mi*12
if(ai<=500000):
tax=0
elif(ai>500000 and ai<=1000000):
tax=(ai-500000)*0.10
elif(ai>1000000 and ai<=2000000):
tax=(500000*0.10)+(ai-1000000)*0.20
else:
tax=(500000*0.10)+(1000000*0.20)+(ai-2000000)*.30
print("Employee Name=",name)
print("Monthly Income=",mi)
print("Annual Income=",ai)
print("Total Income Tax=",tax)
input/output
enter your nameAs
enter monthly Salary54000
Employee Name= As
Monthly Income= 54000.0
Annual Income= 648000.0
Total Income Tax= 14800.0
input/output
enter value of a50
enter value of b25
enter value of c30
Roots are imaginary
➢ #Program on match and case statement (alternative of switch
statement)
# match statement alterntive of switch statement
n=int(input("Enter a day number"))
match n:
case 1:
print("Monday")
case 2:
print("Tuesday")
case 3:
print("Wednesday")
case 4:
print("Thursday")
case 5:
print('Friday')
case 6:
print('Saturday')
case 7:
print('Sunday')
case _:
print("Invalid Day No.")
input/output
>>>Enter a day number5
Friday
>>>Enter a day number7
Sunday
>>>Enter a day number9
Invalid Day No.
input/output
>>>enter your nameraj
Name=raj
>>>enter your nameShivam
Name is not available
>>>enter your nameakash
Name=Akash
input/output
Enter a no5
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
End of program
input/output
>>>Enter a number123
Not armstrong number
>>>Enter a number153
Armstrong number
input/output
Enter a number14641
Number is palindrome
Enter a number151
Number is palindrome
Enter a number152
Number is not palindrome
output:
value of x= 1
value of x= 2
value of x= 3
value of x= 4
value of x= 5
value of x= 6
value of x= 7
value of x= 8
value of x= 9
Example 2:
for x in range(1,11,2):
print("value of x=",x)
output: -
value of x= 1
value of x= 3
value of x= 5
value of x= 7
value of x= 9
Example 3:
x={3.5,1.09,4.59,3.68}
for p in x:
print("element-",p)
output: -
element- 3.68
element- 1.09
element- 3.5
element- 4.59
Example 4:-
str="BBDU"
for i in str:
print(i)
output: -
B
B
D
U
n=int(input("enter a number"))
enter a number8
output: -
8*1=8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80
for i in range(1,11):
print(n,"*",i,"=",(n*i))
else:
print("end of for loop:")
output: -
8*1=8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80
end of for loop:
example 1: -
for i in range(1,6):
for j in range(1,i+1):
print(j,end=' ')
print('')
output: -
1
12
123
1234
12345
example 2:-
for i in range(1,6):
for j in range(1,i+1):
print(j,end=' ')
print("*",end=' ')
print('')
output: -
1*
1*2*
1*2*3*
1*2*3*4*
1*2*3*4*5*
example 3: -
for i in range(1,6):
print(i,end=' ')
for j in range(1,i+1):
print(j,end=' ')
print("*",end=' ')
print('')
output: -
11*
21*2*
31*2*3*
41*2*3*4*
51*2*3*4*5*
x=int(input("enter x"))
y=int(input("enter y"))
z=int(input("enter z"))
r=sarea(x, y, z)
print("Area of Scalene Triangle=",r)
Input/output
enter x5
enter y6
enter z9
Area of Scalene Triangle= 14.142135623730951
x=int(input("enter x"))
y=int(input("enter y"))
z=int(input("enter z"))
r=sarea(x, y, z)
print("Area of Scalene Triangle=",r)
print("")
print("Area of scalene triangle having default=",sarea(8,11)) # default argument
print("Area of scalene triangle having default=",sarea(8,c=12)) # keyword
argument
Input/output
enter x8
enter y9
enter z11
Area of Scalene Triangle= 35.4964786985977
input/output
>>>Enter a number555
Not Spy No.
>>>Enter a number123
Spy No.
➢ #program for fibonacci series
n=int(input("Enter no of terms"))
a=0
b=1
print("Fibonacci Series is:")
print(a, b, end=' ')
i=2
while(i<n):
c=a+b
print(c,end=" ")
a=b
b=c
i=i+1
input/output
Enter no of terms9
Fibonacci Series is:
0 1 1 2 3 5 8 13 21
datetime.datetime.now()
Out[65]: datetime.datetime(2024, 3, 1, 11, 33, 39, 467093)
x=datetime.datetime.now()
x.strftime("%x")
Out[67]: '03/01/24'
x.strftime("%X")
Out[68]: '11:34:20'
datetime.datetime.now().strftime("%X")
Out[69]: '11:36:57'
datetime.datetime.now().strftime("%x")
Out[70]: '03/01/24'
datetime.datetime.now().strftime("%a")
Out[71]: 'Fri'
x.strftime("%H")
Out[72]: '11'
x.strftime("%M")
Out[73]: '34'
x.strtime("%S")
Traceback (most recent call last):
x.strftime("%S")
Out[75]: '20'
Honesty
is
the
best
policy
= RESTART:
C:/Users/rimds/AppData/Local/Programs/Python/Python310/ckp/stringlinears
earch.py
Enter a sentence from usertoday is tuesday
Enter a search keyis
Element found at position= 2
= RESTART:
C:/Users/rimds/AppData/Local/Programs/Python/Python310/ckp/stringlinears
earch.py
Enter a sentence from userrahul is good boy
Enter a search keysumit
Element not found
mystr="BBDU"
print(mystr.center(20,' '))
BBDU
mystr.center(20,'*')
'*BBDU*'
mystr.center(40,'@')
'@@@@@@@@@@@@@@@@@@BBDU@@@@@@@@@@@@@@@
@@@'
mystr.center(39,'$')
'$$$$$$$$$$$$$$$$$$BBDU$$$$$$$$$$$$$$$$$'
mystr.center(9,'*')
'BBDU*'
n='smartphone were distributed yestereday'
n.capitalize()
'Smartphone were distributed yestereday'
input/output
>>>Enter a sentence from userAnimesh
Enter a search keyk
Element not found
>>>Enter a sentence from userShivam
Enter a search keyv
Element not found
➢ #program on string2
print("\\Hello ji")
\Hello ji
print("\'Prime Minister of India is\' \"Narandra Modi\"")
'Prime Minister of India is' "Narandra Modi"
print("Hello \a")
Hello
print("Hello \a")
Hello
print("Hello BBD\f")
Hello BBD
print("Hello BBDU\r")
Hello BBDU
print("Hello BBDU \r We are waiting for you")
Hello BBDU
We are waiting for you
print("Hello BBDU \n We are waiting for you")
Hello BBDU
We are waiting for you
print("Hello BBDU \t We are waiting for you")
Hello BBDU We are waiting for you
print("Hello BBDU \v We are waiting for you")
Hello BBDU
We are waiting for you
print("Hello BBDU \ooo We are waiting for you")
Hello BBDU \ooo We are waiting for you
print("Hello BBDU \0oo We are waiting for you")
Hello BBDU
str="Babu Banarasi Das University"
t=str.find("Das")
print(t)
14
print(str.find("Bhaiya"))
-1
print(str.find("Babu"))
0
print(str.find("babu"))
-1
s=" Mera Bharat Mahan "
s.lstrip()
'Mera Bharat Mahan '
s
' Mera Bharat Mahan '
s.rstrip()
' Mera Bharat Mahan'
s
' Mera Bharat Mahan '
s.istitle()
True
s1="sab padhen sab badhen"
s1.istitle()
False
1.capitalize().istitle()
False
s1
'sab padhen sab badhen'
s2=s1.capitalize()
s2
'Sab padhen sab badhen'
s2.istitle()
False
s2
'Sab padhen sab badhen'
s3="sab"
s3
'sab'
s4=s3.capitalize()
s3
'sab'
s4
'Sab'
s4.istitle()
True
s5="Hello BBDU, we are waiting for you"
s6=s5.partition("we")
s6
('Hello BBDU, ', 'we', ' are waiting for you')
s6=s5.partition(",")
s6
('Hello BBDU', ',', ' we are waiting for you')
s7="I like banana and mango very much."
s7
'I like banana and mango very much.'
s8=s7.replace("banana","papaya")
s8
'I like papaya and mango very much.'
s9="kamal and father of kamal do'nt like friends of kamal"
s9
"kamal and father of kamal do'nt like friends of kamal"
s9.replace("kamal","suhas",2)
"suhas and father of suhas do'nt like friends of kamal"
s10="chandra"
'-'.join(s10)
'c-h-a-n-d-r-a'
srr=" BBDU"
srr
' BBDU'
srr.lstrip()
'BBDU'
srr="BBDU "
srr
'BBDU '
srr.rstrip()
'BBDU'
srr
'BBDU '
srr=srr.rstrip()
srr
'BBDU'
srr
'BBDU'
srr.lower()
'bbdu'
srr
'BBDU'
srr=srr.lower()
srr
'bbdu'
srr=srr.upper()
srr
'BBDU'
srr.islower()
False
srr.isupper()
True
mystr="lucknow"
mystr
'lucknow'
mystr.isalpha()
True
mystr=mystr+"123"
mystr
'lucknow123'
mystr.isalpha()
False
mystr="lucknow 123"
mystr.isalpha()
False
mystr.isdigit()
False
str21="2345"
str21.isdigit()
True
mystr
'lucknow 123'
mystr.isalnum()
False
mystr="lucknow123"
mystr.isalnum()
True
mystr
'lucknow123'
mystr1=' '
mystr1
''
mystr1.isspace()
True
mystr.isspace()
False
s12="we are indians"
s12
'we are indians'
s12.capitalize()
'We are indians'
s12
'we are indians'
s12.istitle()
False
s12=s12.capitalize()
s12
'We are indians'
s12.istitle()
False
s12="Bbdu"
s12.istitle()
True
sent="mother of ankit and father of ankit don't like friends of ankit."
sent
"mother of ankit and father of ankit don't like friends of ankit."
sent.replace("ankit","deepak")
"mother of deepak and father of deepak don't like friends of deepak."
sent.replace("deepak","shivam",2)
"mother of ankit and father of ankit don't like friends of ankit."
sent=sent.replace("ankit","deepak")
sent
"mother of deepak and father of deepak don't like friends of deepak."
sent.replace("deepak","shivam",2)
"mother of shivam and father of shivam don't like friends of deepak."
nst=" All are Indians "
nst
' All are Indians '
nst.lstrip()
'All are Indians '
nst
' All are Indians '
nst=nst.lstrip()
nst
'All are Indians '
nst=nst.rstrip()
nst
'All are Indians'
nst="bbdu"
nst
'bbdu'
nst.istitle()
False
nst=nst.upper()
nst
'BBDU'
nst=nst.lower()
nst=nst.capitalize()
nst
'Bbdu'
nst.istitle()
True
nst="Pure hote wade"
nst
'Pure hote wade'
nst.istitle()
False
st="teachers of bbdu and heads of bbdu are best in all bbdu colleges."
st=st.replace("bbdu","Lucknow University")
st
'teachers of Lucknow University and heads of Lucknow University are best in all
Lucknow University colleges.'
st=st.replace("Lucknow University","LCC",2)
st
'teachers of LCC and heads of LCC are best in all Lucknow University colleges.'
st1=st.partition("in")
st1
('teachers of LCC and heads of LCC are best ', 'in', ' all Lucknow University
colleges.')
st1[0]
'teachers of LCC and heads of LCC are best '
st1[1]
'in'
st1[2]
' all Lucknow University colleges.'
st
'teachers of LCC and heads of LCC are best in all Lucknow University colleges.'
st3="teachers of LCC and heads of LCC are best in \n all Lucknow University
colleges."
st3
'teachers of LCC and heads of LCC are best in \n all Lucknow University
colleges.'
print("teachers of LCC and heads of LCC are best in \n all Lucknow University
colleges.")
teachers of LCC and heads of LCC are best in
all Lucknow University colleges.