Python 7.00-9.00
Python 7.00-9.00
why used
when used
====================================
program?-->question-->answer-->programming way.
1.start
2.input
3.calculation
4.display
5.stop
-----------------------------------------------------------------------
variable and datatype:--
feature of datatype:
1.int-->no decimal value-->whole number-->e.g-->86,10000,7456.--->%d
4.string-->word,paragraph,sentences-->"hello",''hdgdghsdg shghs".-->%s
5.boolean-->true or false.
============================================
Employee Details:
----------------------------------------
Emp_id=101
Emp_Name="Kavita"
Salary=65000.00
Address="hyd"
=============================
Addition of two no:
Num1=55
Num2=74
Num3=Num1+Num2
print("Addition of two no is",Num3)
--------------------------------------------------
1.,
2.%
3..Format()--->{0}
print(Num3)
print("Addition of two no is:%d"%Num3)
print("Sum of two no is:",Num3)
print("Num1:{0} and Num2:{1} and Num3:{2}".format(Num1,Num2,Num3))
-----------------------------------------------------------------------
Input Function:take value from user.
string-->float-->float()
a="welcome"
print(a)
a=45
print(a)
del a
print(a)
==========================================
-----------------------------------------------------------------
Addition of two no without variable take value from user:-
type of operator:
1.arthimetic:-->+,-,*,/,%-->two operand.
write a program to calcaulte salary slip-->employeee-->take value from user basic
salary,
DA-->Dearness allowness-->bs of 5 %.
HRA-->housing Rent allowance-->bs of 7%
traveling-->1500
PF:-->bs of 8%
TDS:-->bs of 5%
PT-->bs of 6%
gross_salary=Basic_sal+DA+HRA+Travelling
tax=pf+tds+pt
net_sal=(gross_salary)-(tax)
a=25
b=10
sum=a+b
sub=a-b
mul=a*b
div=a/b
mod=a%b
print("Add:",sum)
print("Substract:",sub)
print("Multiply:",mul)
print("Division:",div)
print("Modulus:",mod)
2.Assignment:-->+=,-=,*=,/=,%=--->one operand.
Num=100
print(Num)
Num+=200
#100+200=num
print(Num)
Num-=150
print(Num)
Num*=5
print(Num)
3.Logical:-->And,Or,Not.
iii.Not-->opposite of condition.
cond result
1 0
0 1
4.Comparison:--><,>,<=,>=,==,!=.
5.Bitwise:-->binary value
and,or,xor,not:-->binary value.
00001010-->10
00001000-->20
-------------------
00001000
6.Special operator:
Num1=100
Num2=200
print(Num1 is Num2)
print(Num1 is Not Num2)
ii.Membership:in,not in(string,list,tuple,dict)
x="welcome"
print('c' in x)
print('j' not in x)
y=[1,2,3,4]
print(3 in y)
z=(7,8,9,10)
print(11 in z)
a={1:"jai",2:"kavita",3:"sunil"}
print(2 in a)
==================================
Decision Making:-->
example-->condition-->
question-->score greater than 35.,age should be greater than 18.
Logical:-->and,or,not
Comparison:-->,<,<=,<=,==,!=
---------------------------------------------------------------------------
1. if(condition):
statement
2.if(condition):
statement
else:
statement
mark=15
if(mark>=35):
print("pass")
else:
print("Fail")
---------------------------------
no=91
if(no%2==0):
print("Even No:",no)
else:
print("Odd No:",no)
-------------------------------------
n1,n2=98,780
if(n1>n2):
print("Number1 is greater:",n1)
else:
print("Number2 is greater:",n2)
-------------------------------------------------
age=int(input("Enter Age:"))
if(age>18):
print("Eligible for voting")
else:
print("Try again")
-----------------------------------------------------
mark=5
att=65
if((mark>=35)and(att>=65)):
print("Pass")
else:
print("fail")
3.Multiple if:
if(condition):
statement
if(condition):
statement
if(condition):
statement
n1,n2,n3=99,99,100
if((n1>n2)and(n1>n3)):
print("Number 1 is greater",n1)
if((n2>n1)and(n2>n3)):
print("Number 2 is greater",n2)
if((n3>n1)and(n3>n2)):
print("Number3 is greater",n3)
4.Nested If:
if(condition):
if(condition):
statement
else:
statement
else:
statement
--------------------------------------------
mark=5
att=85
if(mark>35):
if(att>65):
print("pass")
else:
print("mark are greater but not att")
else:
print("try again")
-------------------------------------------------
n1=100
n2=200
if(n1==100):
if(n2==200):
print("both no r equal")
else:
print("n1 is equal but not n2")
else:
print("Both no r not equal")
5.if elif:
if(condition):
statement
elif():
statement
elif():
statement
else:
statement
ch='y'
if((ch=='A')or(ch=='a')):
print("character is vowel",ch)
elif((ch=='I')or(ch=='i')):
print("character is vowel",ch)
elif((ch=='E')or(ch=='e')):
print("character is vowel",ch)
else:
print("character is not vowel",ch)
========================================
1.write a program to check login-->take username and pwd.
username=admin
pwd=admin123
-->login successfully
-->username is correct but not pwd
-->try again
percent grade
80 A+
70 A
60 B
50 C
40 D
=========================================================
decision-->condition-->
loop:-->repeat task-->10,100,150.
type of loop:
1.while loop:
syntax:
while(condition):
statement
increment/decrement
no=1
while(no<=10):
print(no)
no=no+1 #1+1=2+1=3+1=4
-----------------------------------------------
reverse order:
no=10
while(no>=1):
print(no)
no=no-1
----------------------------------------------
#print 1 to 20,print even no.
while(no<=end):
if(no%2==0):
print("Even no",no)
no=no+1
-------------------------------------------------------
sum of given no.-->1-5.
-------------------------------------------------------
start=int(input("Enter start no:"))
end=int(input("Enter end no:"))
sum=0
while(start<=end):
sum=sum+start
print(sum)
start=start+1
#print(sum)
1
3
6
10
15
=====
15
======
2.for loop:-->string,tuple,list.
syntax:
========================
for i in sequence:
print()
-------------------------------------------
str="welcome"
for i in str:
print(i,end="")
print(" ")
list_1=[101,102,103,104,105]
for j in list_1:
print(j)
tup=('H','e','l','l','o')
for k in tup:
print(k,end="")
======================================
1.Take no from user and print in table format like this:
Enter No-->5
5*1=5
5*2=10
5*3=15
5*10=50
for-->list(range(start,end,step-->increment)-->)
range:
break:
continue:
--------------------------------------------------
print(list(range(1,11)))
print(i)
print(list(range(2,21,2)))
print("Even:",i)
print(list(range(1,21,2)))
print("odd",i)
for i in range(1,21,2):
print(i)
---------------------------------------------------
for i in range(1,21,1):
if(i==10):
#break
continue
print(i)
---------------------------------------------
str="welcome"
for i in str:
if(i=='c'):
break
print(i,end="")
---------------------------------------------
print(" ")
str="welcome"
for i in str:
if(i=='c'):
continue
print(i,end="")
----------------------------------------------
string:
input()-->string.-->variable.
-------------------------------------------------
once assign the value of string cannot change.-->immutable.
but we can reassign the variable.
str='computer'
print(str)
str[0]='k'
print(str)
str="data"
print(str)
----------------------------------------------------------------
way of declare of string variable:-
----------------------------------------------------------------
str='Welcome'
print(str)
print(greet[6])
2.Index/range:
greet='Welcome'
print(greet)
print(greet[0:4])
print(greet[0::])
print(greet[-1])
print(greet[::-1])
3.Membership:-->In,Not In
s1='computer'
print('p' in s1)
usernm="Admin"
pwd="Admin123"
5.Concatecation:-->+
s1="hello"
s2="world"
print(s1+s2)
-------------------------------------
t1="computer"
t2=63
print(t1+str(t2))
6.Repeat:-->*
s1="hello"
print(s1 * 3)
=================================
Method:-->string:
1.lower():
2.upper()
3.capitalize()
4.join
5.index
6.startwith
7.endwith
8.len
9.contain
10.reversed
--------------------------------------------------------------
str="welcome"
print(str.upper())
print(str.lower())
print(str.capitalize())
print("*".join(str))
print("".join(reversed(str)))
s2="data science"
print(s2.replace("science"," analytics"))
print(s2.index('c'))
print(len(s2))
print(str.startswith('t'))
print(str.endswith('o'))