python learning
python learning
Variables a,b,c
Integer 1,2,3,
Operator =,+
Python 2
Stringe “”
Stringe became an integer is we put before like int (“”).now we get integer.
20 we get 1020
Multiply **
Add+++
PYTHON 3
Comparison operator;
Sample1
input
Kaveri=input()
If(kaveri==”wife”):
Print(“yes”)
Else:
Print(“no”)
Output
Wife-yes
No-no
Python 4 casting
If(she>12):
Print(“yes she”)
Else:
2. modules
A=19
Print(A%2)
Example: a=int(input())
Else:
Ans: 90 ,else
100,if is will be give
Python 5
A=int(input( “number”))
If (a%2==0):
Print(“add”)
Else:
Pprint(“odd”)
Ex 2-score
Score=int (input(“score”))
If(score<35):
Print(“bad student”)
If(score>35 and score<70) (but we have to implent the rule is elif) second if changes like(elif)but
not 3rd it may be more than 6 or etc but last is else if will be change like (else)
If (score>70):
Output-score: wt we want
2 Elif example
Score=int(input())
If(score<35):
Print(‘’”)
Print(“”)
Elif(score>70 and score>100):
Print(“”)
Else:
Print(‘”)
Output=score:wt we want
3rd example
a=int(input("a:"))
b=int(input("b:"))
operation=input("add/sub/mul/div:")
if(operation=="add"):
print(a+b)
elif(operation=="sub"):
print(a-b)
elif(operation=="mul"):
print(a*b)
elif(operation=="div"):
print(a/b)
else:
print("invalid")
4th example
if(score>=70):
name=input("enter your name")if question like his name ,age asked the question we add (if )under.i
mentioned it susmi carefully see.
age=input("enter your age")
print("eligible")
else:
print("not eligible")
python 6
ex 1
a=int(input("enter a number:"))
if(a%2==0):
print("even")
else:
print("odd")
ex 2
salary=int(input("salary:"))
age=int(input("age:"))
if(salary>=20000 or age<=25):
print("you r eligible")
else:
print( "eligible")
ex 3
salary=int(input("salary:"))
age=int(input("age:"))
if (salary<=40000 or age>=43):
loan=int(input("laon:"))
if(loan<=50000):
else:
print("eligible")
else:
print("not eligible")
python 7 excericis
starting 0
ex 1
for i in "apple":
print(i)
out put-a
e
2. ex
for i in range(5):
print(i)
output 0
Ex 3
for i in range(1,7):
print(i)
output
Ex 4
Question 1x2=2
2x2 =4
input
for i in range(1,11):
print(i,"x2=",i*2)
output-1x2=2
2x2=4
Eg 5
a=int(input())
b=int(input())
print(i)
output ; wt we want
eg 6
if(i%2==0):
print(i)
output; 2,4,,6,8,10
eg7
count=0
if(i%2==0):
count=count+1
print(count)
output 5
eg7
e_count=0
o_count=0
for i in range(1,11):
if(i%2==0):
e_count=e_count+1
else:
o_count=o_count+1
print(e_count)
print(o_count)
output: 5
Eg 9
count=0
count=count+1
print(count)
output 6
18-11-2024
LIST[]=[a,b,d,c,]
1) sum=0
sum=sum+i
print(sum)
output=15
2) a=[]
a.append(10)
a.append(20)
a.append(30)
a.append(40)
print(a)
output =[10,20,30,40]
a=[]
print("Enter 10 numbers:")
a.append(num)
print(a)
sum=0
for i in a:
sum=sum+i
print(sum)
for i in range(1,6):
for j in range(1,3):
print(j,"apple")
OUTPUT, 1 apple
2 apple
1 apple
2 apple
1 apple
2 apple
1 apple
2 apple
1 apple
2 apple
for i in range(1,3):
print("week:",1)
print("day:",j)
output:
week: 1
day: 1
day: 2
day: 3
week: 1
day: 1
day: 2
day: 3
for i in range(1,5):
print()
print(j,end="")
output:
12
123
1234
for i in range(1,5):
print()
print(end="*")
**
***
****
Day 12
While loop
1) i=0
while(i==0):
print(i)
output: 000000000
2) i=1
while(i<5):
print(i)
i=i+1
output:1
4
3) i=10
while(i<=200):
print(i,end=”,")
i=i+10
output
10,20,30…200
4) i=10
while(i>0):
print(i,end=",")
i=i-1
output: 10,9,8,7,6,5,4,3,2,1
5)i=4
fact=1
while(i>0):
fact=fact*i
i=i-1
print (fact)
output=6
26\11\2024collection python
List[]=>
Set
dictonary
LIST-APPEND,EXTEND,POP,INSERT
1)APPEND
a=[1,2,3,4,5]
print(a)
a.append(7)
a.append(8)
print(a)
output= 91,2,3,4,5,6,7)
2) a=[1,2,3,4,5,6]
print(a[1])
output=2
3) INSERT
a=[1,2,3,4,5,6]
a.insert(0,11)
print(a)
output=(11,1,2,3,4,5,6)
4) a=[1,2,3,4,5,6]
a[0]=11
print(a)
output=(11,2,3,4,5,6)
POP
5) a=[1,2,3,4,5,6]
a.pop(5)
print(a)
output(1,2,3,4,5)
6)EXTEND
a=[1,2,3,4,5,6]
b=[22,34,56]
a.extend(b)
print(a)
ii TUPLE()=>
a=[1,2,3,4,5,6]
b=list(a)
b.pop()
print(a)
print(b)
OUTPUT=(1,2,3,4,5,6)
( 1,2,3,4,5,)
SET
a={1,2,3,4}
a.add(10)
print(a)
output :1,2,3,4,10
DICTIONARY
1) a={"name":"emc"}
print(a)
ouput: “name”:”emc”
2) a={
"name":"emc",
"age":1,
"location":"pudukottai",
"students":["bala","arun"]
print(a)
3) a={
"name":"emc",
"age":1,
"location":"pudukottai",
"students":["bala","arun"]
a["colour"]="red"
print(a)
14. 4\12\2024-functions
1) def painter():
print("painting")
painter()
output:painting
2) def add():
a=int(input())
b=int(input())
print(a+b)
print("ok")
add()
output:ok
10
20
30
print("addition")
a=int(input("print a"))
b=int(input("print b"))
print(a+b)
add()
output:addition:
print a:10
print b:20
30
print("multifliction")
a=int(input("print A:"))
b=int(input("print b:"))
print(a*b)
mul()
def div():
print("division")
a=int(input("print a:"))
b=int(input("print b:"))
print(a%b)
div()