0% found this document useful (0 votes)
15 views13 pages

Python 7.00-9.00

This document provides an overview of Python programming concepts, including variables, data types, operators, decision-making, loops, and string manipulation. It outlines the structure of a basic program, demonstrates input and output operations, and explains various operators and control flow statements. Additionally, it includes examples of employee details, calculations, and user interactions to illustrate the application of these concepts.

Uploaded by

Fawaz Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Python 7.00-9.00

This document provides an overview of Python programming concepts, including variables, data types, operators, decision-making, loops, and string manipulation. It outlines the structure of a basic program, demonstrates input and output operations, and explains various operators and control flow statements. Additionally, it includes examples of employee details, calculations, and user interactions to illustrate the application of these concepts.

Uploaded by

Fawaz Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

what is python

why used
when used
====================================

program?-->question-->answer-->programming way.

1.start
2.input
3.calculation
4.display
5.stop

-----------------------------------------------------------------------
variable and datatype:--

feature of variable:---<used to store the value.


1.Name:
2.Value:
3.Address:

feature of datatype:
1.int-->no decimal value-->whole number-->e.g-->86,10000,7456.--->%d

2.float:-->decimal value-->precision 6 digit-->e.g-->65.000000-->%f

3.double:-->decimal value-->12 digit-->65.001475236-->%lf

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

Formatting the display:

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.

input-->return the value in string form.


-------------------------------------------------
converting:
-----------------------------------------
string--->int-->int()

string-->float-->float()

string-->string-->no need of converting the data.


====================================
variable-->change the value.

a="welcome"
print(a)

a=45
print(a)

del a
print(a)
==========================================

Stud_id=int(input("Enter Student Id:"))


Name=input("Enter Name:")
Mark=float(input("Enter Student Mark:"))
Result=input("Enter Result:"))

print("Your Student ID:",Stud_id)


print("Your Student Name:%s"%Name)
print("Your Mark:",Mark)
print("Your Result:{0}".format(Result))

-----------------------------------------------------------------
Addition of two no without variable take value from user:-

print("Addition of two no is:",int(input("Enter Number1:"))+int(input("Enter


Number2:")))
==============================================
day2:operator
==============================================
operator-->expression-->a+b-->a,b-->operand,+-->operator.

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.

i.And:-->more than two condition must be true.

cond1 cond2 result


0 1 0
0 0 0
1 1 1

ii.OR-->one condition must be true.

Cond1 Cond2 result


1 0 1
1 1 1
0 0 0

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:

i.identity:is,is not(check the value between two variable)

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

#to check vowel character:a,i,e,o,u

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

2.write a program to check voting eligibllity-->take value from user-->age,citizen


age-->greater than 18
citizen-->india
-->voting eligible
-->age is valid but not citizen
-->NRI

3.write a program to check discount on customer product.


take value from user-->cust_id,prod_price-->5,total.

total--greater than 6500-->5%


total--greater than 5500-->4%
total--greater than 4500-->3%
total--greater than 3500-->2%
calculate-->total,discount,actamt.

4.create a marksheet of student -->take value from user-->Stud_id,Nm,6 subject


mark,
total,percent,grade,result-->6 subject--<score-->35-->pass,fail.

percent grade
80 A+
70 A
60 B
50 C
40 D
=========================================================
decision-->condition-->

variable:-->at a time only one value.


execute so many time-->

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.

no=int(input("Enter Start Number:"))


end=int(input("Enter End Number:"))

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

2.print even and odd no from 1 to 20.


odd no:1
even no:2
odd no:3
even no:4
even no:20
---------------------------------------------------

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:

what is string-->datatype:-->value-->"word",' ',""" """


int,float:-->

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)

str1="Excellenc Toward Growth"


print(str1)

str3='''this is data analytics ruruy hgdh bvvbv '''


print(str3)
========================================
take value from user:-->
---------------------------------------------------------------------------
Cour_nm=input("Enter Course Name:")
fees=float(input("Enter fees:")

print("Your Course Name:%s"%Cour_nm)


print("Your Fees:%f"%fees)
===================================
String operator:
----------------------------------------------------------------
1.slice:
greet='Welcome'
print(greet)

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)

print('y' not in s1)


4.Raw string:-->\n

usernm="Admin"
pwd="Admin123"

print("Your UserName:",usernm,"\n","Your Password:",pwd)

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

You might also like