Python 1
Go to file ,click new file,save as document in python folder.
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.
How we get input from users -10
20 we get 1020
Now we give input like int (input()) we get answer like 30
Multiply **
Add+++
Divide/// also -% modules
The code is =input(),print(“:,”)
The integer code is =int (input()),print(“:”,)
PYTHON 3
False amd true word first letter will be capital
IF (TRUE): ,PRINT (“YES”)
ELSE –print (“no”)
Boolean value-true and false are known.
Comparison operator;
Print(“win”=”win”) –true,=(before and after same)
Print (“win”=winn”)-false,=(before and after are not same).
Sample1
input
Kaveri=input()
If(kaveri==”wife”):
Print(“yes”)
Else:
Print(“no”)
Output
Wife-yes
No-no
Python 4 casting
1 ,She=int(input()) –suppose we want inside input like she we put ,she=int(input(“she”)
If(she>12):
Print(“yes she”)
Else:
(“no she”). Ans:11,no she,,,,,,ans:13,yes she
Bineary operator=and ,or,not
2. modules
A=19
Print(A%2)
Ans :is 2 not divisible,otherwise we get 0 is divisible.
Example: a=int(input())
If (a%10==0 and a%20==0):
Print(“divisible by !0 and 20”)
Else:
Print(“not divisible by 10 and 20”)
Ans: 90 ,else
100,if is will be give
Python 5
Ex 1 –the number is even or odd
A=int(input( “number”))
If (a%2==0):
Print(“add”)
Else:
Pprint(“odd”)
Output---number:4 will be come even
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)
Print(“average student”) 1-st if ,2nd-elif, 3rd-elif……,last-else.
If (score>70):
Print (“good student”)
Output-score: wt we want
2 Elif example
Score=int(input())
If(score<35):
Print(‘’”)
Elif(score<35 and score>70):
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
score =int(input("score percentage:"))
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
nested if mean we have add another if is called nested if
salary=int(input("salary:"))
age=int(input("age:"))
if (salary<=40000 or age>=43):
loan=int(input("laon:"))
if(loan<=50000):
print("maximam loan is 50000")
else:
print("eligible")
else:
print("not eligible")
python 7 excericis
python 8-for loop
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
Set of letters or range is given be like.
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())
for i in range (a+1,b):
print(i)
output ; wt we want
eg 6
for i in range (1,11):
if(i%2==0):
print(i)
output; 2,4,,6,8,10
eg7
count=0
for i in range (1 ,11):
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
for i in range (1,101):
if(i%3==0 and i%5==0):
count=count+1
print(count)
output 6
18-11-2024
LIST[]=[a,b,d,c,]
1) sum=0
for i in range (1,6):
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:")
for i in range (5):
num=int (input("Enter num"+str(i+1)))
a.append(num)
print(a)
sum=0
for i in a:
sum=sum+i
print(sum)
NESTED FOR LOOP
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)
for j in range (1,4):
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()
for j in range (1,i+1):
print(j,end="")
output:
12
123
1234
for i in range(1,5):
print()
for j in range (1,i+1):
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[]=>
Tuple()=>cannot modify and not add or remove
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
3.) def add():
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
4.) def mul():
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()