0% found this document useful (0 votes)
54 views12 pages

Phyton

The document provides examples of various Python programming concepts like string formatting, data types, arithmetic and logical operators, conditional statements, loops, lists, indexing, and slicing. Some key points covered include: 1) Examples are given for string formatting using escape sequences like \n and \t, printing variables, taking user input, and performing arithmetic operations. 2) Conditional statements like if-else and logical operators like >, <, == are demonstrated to check conditions and print outputs. 3) Loops like for loops are used to iterate through ranges and lists. 4) Lists are used to store multiple data types, and indexing and slicing are shown to access specific elements.

Uploaded by

Yasmin Mohammed
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)
54 views12 pages

Phyton

The document provides examples of various Python programming concepts like string formatting, data types, arithmetic and logical operators, conditional statements, loops, lists, indexing, and slicing. Some key points covered include: 1) Examples are given for string formatting using escape sequences like \n and \t, printing variables, taking user input, and performing arithmetic operations. 2) Conditional statements like if-else and logical operators like >, <, == are demonstrated to check conditions and print outputs. 3) Loops like for loops are used to iterate through ranges and lists. 4) Lists are used to store multiple data types, and indexing and slicing are shown to access specific elements.

Uploaded by

Yasmin Mohammed
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/ 12

"\n" makes the charachter to make a new line.

"\t" is used to make space which is known as escape sequence.

print("welcome to \nideal indian school \nDOHA\tQATAR")

Name="Praise"
AGE=16
Fee=5000.45

print(Name)
Print(AGE)
Print(Fee)

print("Name=",Name)
print('age:',AGE)
print("Fee=",fee)

print("Name=",Name,'age',AGE,"FEE=",fee)

------------------------
Name=input("Enter your Name")

#ADDITION OF TWO NUMBERS


A=10
B=20
C=A+B
print("C=",C)

A=int(input("Enter the value of A:"))


B=int(input("Enter the value of B:"))
C=A+B
print("C=",C)

-----------------------------
LENGTH=10
BREADTH=20

LENGTH= int(input("Enter the length:"))


BREADTH=int(input("Enter the breadth:"))

LENGTH=float(input("Enter the length:"))


BREADTH=float(input("Enter the breadth:"))

AREA=LENGTH*BREADTH
PERIMETER=2*(LENGTH+BREADTH)

print("AREA=",AREA)
print("PERIMETER=",PERIMETER)

-------------------------------------------

S=float(input("Entre SIDE:"))

AREA=S*S
PERIMETER=4*S

print("AREA=",AREA)
print("PERIMETER=",PERIMETER)
--------------------------------------------
CIRCLE

r=float(input("Enter RADIUS:"))

PI=3.14

CIRCUMFERENCE=2*3.14*r
AREA=3.14*r*r

CIRCUMFERENCE=2*PI*r
AREA=PI*r*r

print("CIRCUMFERENCE=",CIRCUMFERENCE)
print("AREA=",AREA)

-----------------------------------------------
CONVERTING STRING TO INTEGER
A=int("10")
A=A+20
print(A)

------------------------------------------------
STRING VARIATION
B="20"
B=B+"50"
print("B=",B)

A=int(input("Enter the value of A:"))


B=int(input("Enter the value of B:"))
C=A-B
print("C=",C)

ARITHMATIC OPERATORS +,-,*,/,//

A=int(input("Enter the value of A:"))


B=int(input("Enter the value of B:"))
C=A//B
print("C=",C)

A=int(input("Enter the value of A:"))


B=int(input("Enter the value of B:"))
C=A**B
print("C=",C)

A=int(input("Enter the value of A:"))


B=int(input("Enter the value of B:"))
C=A*B
print("C=",C)

A=int(input("Enter the value of A:"))


B=int(input("Enter the value of B:"))
C=A/B
print("C=",C)
---------------------------------------------

SIMPLE AND COMPOUND INTREST


----------------------------------------------------
PRINCIPLE= float(input("Enter PRINCIPAL:"))
RATE= float(input("Enter RATE:"))
TIME= float(input("Enter TIME:"))

SI= (PRINCIPLE*RATE*TIME)/100
CI= PRINCIPLE *(1+RATE/100)**TIME

print("SI=",SI)
print("CI=",CI)

P=float(input("enter p:"))
r=float(input("enter r:"))
t=float(input("enter t:"))
SI=p*r*t/100
CI=p*(1+r/100)**t
print("SI=",SI)
print("CI=",CI)
====================================================
COST PRICE and SALE PRICE

cost_price=float(input("enter cp:"))
perc=float(input("enter d:"))

discount=cost_price*perc/100
sale_price=cost_price-discount

print("sale price=",sale_price)

======================================================
#if statement
======================================================
num=-4
if num>0:
print("Positive Number")
print("Welcome to IIS")
-------------------------------------------------
elif num==0:
print("Number is Zero")

else:
print("Negative Number")

print("DOHA QATAR")
===================================================
#if else statement
num=-4
if num>0:
print("Positive Number")
print("Welcome to IIS")
==================================================
#IF ELIF ELSE STATEMENT
num=int(input("Enter a Number:"))
if num>0:
print("Positive Number")
**************************************************
#odd and even number

num = int(input("Enter a number: "))


if (num % 2) == 0:
print(" even number")
else:
print("odd number")
--------------------------------------------------

#TO FIND A AVERAGE AND GRADE FOR GIVEN MARKS.


eng=float(input("Enter English Marks:"))
ip=float(input("Enter IP Marks:"))
phy=float(input("Enter physics Marks:"))
chem=float(input("Enter Chemistry Marks:"))
maths=float(input("Enter Maths <arks:"))

average=float((eng+ip+phy+chem+maths)/5)
print("Average of Marks is",average)

if average>90:
print("You scored GRADE A")
elif average>80 and average<=90:
print("You scored GRADE B")
elif average>60 and average<=80:
print("You scored GRADE C")
elif average>=35 and average<=60:
print(:You scrored GRADE D")
else:
print("You scored GRADE E")
===============================================
#TO FIND SALE PRICE OF AN ITEM WITH GIVEN COST AND DISCOUNT (%)
Cost_Price=float(input("Enter the cost Price:"))
perc=float(input("Enter the Discount%:"))

Discount=Cost_Price*perc/100
Sale_Price=Cost_Price-Discount
print("Sale Price=",Sale_Price)
==============================================
actual_cost=float(input("Please Enter the Actual Product Price:"))
sale_amount=float(input("Please Enter the Sales Amount:"))

if(actual_cost>sale_amount):
amount= actual_cost-sale_amount
print("Total Loss Amount:", amount)

elif(sale_amount>actual_cost):
= sale_amount-actual_cost
print("Total Profit=", amount)
else:
print("No Profit No Loss!!!")
=================================================
#PYTHON PROGRAM TO CHECK THE INPUT NUMBER IS ODD OR EVEN

num=int(input("Enter a number:"))
if num (num % 2)==0
print("Number is Even")
else:
print("Number is odd"))
================================================
#LOOP
for i in range(0,5)
print(i)
print("Hello")

print
=================================================
for Yusra in range(2,8):
print("Yusra=",yusra)

for x in range(10):
print("x=",x)

for y in range(2,10,2):
print("y=",y)

for z in range(1,11,3):
print("z=",z)

for a in range(11,1,-1):
print("a=",a)

for b in range(11,1,-3):
print("b=",b)
===================================================
n=int(input("Enter n:"))
sum=0

for i in range(1,n+1)
print(i)
sum=sum+i

print("SUM=",sum)
=====================================================
start=int(input("Enter Start:"))
end=int(input("Enter End:"))

sum=0

for i in range(start,end+1):
print(i)
sum=sum+i

print('sum=',sum)
====================================================
start=2
end=10
for i in range(start,end+1,2):
print(i)
----------------------------------------------------
for i in range(2,20,2)
print(i)
---------------------------------------------------
start=int(input("Enter Start:"))
end=int(input("Enter Start:"))

for i in range(start,end+1,2):
print(i)
======================================================
start=int(input("Enter Start:"))
end=int(input("Enter end:"))
sum=0

if start%2==1:
start=start+1

for i in range(start,end+1,2):
print(i)
sum=sum+i

print("sum=",sum)
=========================================================
Display natural number in reverse order between two limits and display numbers?

start=int(input("Enter Start:"))
end=int(input("Enter end:"))
sum=0

for i in range(start,end-1,-1):
print(i)
sum=sum+i

print("sum=",sum)
=========================================================
sum=0

for i in range(1,101,1):
sum=sum+i*i
print('Sum=',sum)
=========================================================
m=int(input("Enter the number"))
n=int(input("enter the limit"))

for i in range(1,n+1):
print(m,"x",i,"=",m*i)
=========================================================
FACTORIAL OF A NUMBER

num = int(input("Enter a number: "))


factorial = 1
if num < 0:
print(" Factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
--------------------------------------------------------
start=int(input("enter a number"))
end=1

product=1

for i in range(start,0,-1):
product=product*i

print("product=",product)
========================================================
a=10
b=20
a +=b
print(a)
========================================================
a=10
b-20
a *=b
print(a)

a=20
b=11
a /=b
print(a)
====================================================
x,y,z=10,20,30
print(x)
print(y)
print(z)
---------------------------------------------------
x,y,z=10,20,30
print(x)
print(y)
print(z)

z,y,x=x+1,z+10,y-10

print(x,y,z)
==================================================
x=100
y=100.45
print(type(x))
print(type(y))

x=y
print(x)
print(type(x))

z=int(y)
print("z=",z)
print(type(z))
-----------------------------------------------------------
#implicite convertion and explicite convertion
a=10
m=float(a)
print("m=",m)
print(type(m))
=============================================================
#logic error
a=(10+20)

avg=67+70/2
print("avg=",avg)

avg(67+70)/2
print("avg=",avg)

z=100/0 #run error


print(z)
----------------------------------------------------------------------
list is a data structure, where we can store things, it is the structure of the
data.

marks={90,89,95,94,99}
print("Marks=",marks)

student1=('Abeer',11,'E',458.62)
print("Student=",student1)

vowels= ['a','e','i','o','u']
print("vowels=",vowels)

List1=[]
print("list1=",List1)

DOB="26-09-2005"
print("DOB=", DOB)

DOBList=list(DOB)
print(DOBList)
======================================================================
#tuple
school=('iis',"mes","dps")
print("schools=",school)

list1=list(school)
print("list=",list1)

name=input("enter your name")


print("name=",name)

list2=list(name)
print("list2=",list2)
=====================================================================
L1=[10,20,30,40,50,60]
# 0 1 2 3 4 5

#INDEXING
print("L1[1]=",L1[1])

print("L1[0]=",L1[0])

print("L1[-1]=",L1[-1])

#SLICING
print("L1[1:4]=",L1[1:4])
print("L1[-6:-3}=",L1[-6:-3])
print("L1[1:]=",L1[1:])
print("L1[4:]=",L1[4:])
print("L1[:]=",L1[:])
=================================================
# -6 -5 -4 -3 -2 -1
L1=[10,20,30,40,50,60]
# 0 1 2 3 4 5
#INDEXING
print("L1[1]=",L1[1])
print("L1[0]=",L1[0])
print("L1[-1]=",L1[-1])

#SLICING

print("L1[1:4]=",L1[1:4])
print("L1[-6:-3}=",L1[-6:-3])
print("L1[1:]=",L1[1:])
print("L1[4:]=",L1[4:])
print("L1[:]=",L1[:])
#LOOP
for x in L1:
print(x)

for x in L1:
print(x+10)

for i in range(len(L1)):
print(i)
print(L1[i])
===================================================
#concatenation (add two lists)
L1=[10,20,30]
L2=[30,40,50]
L3=L1+L2
print('L3=',L3)
=============================================
#repetiiton/replicatoon
print('REPEATING 2 TIMES=',L1*2)
print('REPEATING 3 TIMES=',L2*3)
print('L1=',L1)
L1=L1*2
print('L1=',L1)
=========================================
#UPDATING AND MANIPULATING LISTS
LIST1=[10,20,30,40,50]
print('LIST1[0]=',LIST1[0])

LIST1[0]=100
print('LIST1=',LIST1)

print('LIST1[1:4]=',LIST1[1:4])
LIST1[1:4]=200,300,400
print('LIST1=',LIST1)
============================================
#APPEND () METHOD IS USED TO ADD
L1=[10,20,30]
print('L1=',L1)
L1.append(190)
print('L1=',L1)
#EXTEND() ADDS ONE LIST AT THE END
L1=[10,20,30]
L2=[30,40,50]
print('L1=',L1)
print('L2=',L2)
L1.extend(L2)
print('L1=',L1)
===================================
#DELETE[] AND POP()
L1=[10,20,30,40]
print('L1=',L1)

del L1[3]
print('L1=',L1)

L1.pop(2)
print('L1=',L1)
==============================
LIST1=[10,20,30,40,50,60,10,20]
print('LIST1=',LIST1)

print('index of 40:',LIST1.index(40))
print('count=',LIST1.count(20))
print('length=',len(LIST1))
print('maximum=',max(LIST1))
print('minimum=',min(LIST1))
LIST1.reverse()
print('reverse=',LIST1)
LIST1.sort()
print('sort=',LIST1)
================================
LIST1=[10,20,30,40,50,60]
print('LIST1=',LIST1)
LIST1.insert(1,15)
print('LIST1=',LIST1)
LIST1.insert(0,100)
print('LIST1=',LIST1)
LIST1.remove(20)
print('LIST1=',LIST1)
=============================
#MEMBERSHIP TESTING
LIST1=[10,20,30,40,50,60]
print('LIST1=',LIST1)
print (40 in LIST1)
print (1000 in LIST1)
print(20 in LIST1)
========================
#CLEAR
lst=[15,20,45,60]
print('before clear=',lst)
lst=[]
print('after clear=',lst)
=================================
#tuple
t1=('iis')
print(t1)
fruits=('mango','apple')
print('fruits')
n=(10,20,30)
print(n)
=================================
#lab programme 1(pdf of list page 10)

n=int(input("enter how many friends?"))

l=[]

for i in range(n):
name=input("enter friend name:")
l.append(name)

print("friend list",l)
======================================
LAB PROGRAMME 2
l=[]
n=int(input("enter total number of values in list:"))
for i in range(1,n+1,1):
a=int(input("enter the list element:"))
if(a%2==0):
l.append(a)

print("list=",l)
==============================================
# even number list
n=int(input('how many numbers?:'))
evenlist=[]

for i in range(n):
num=int(input('enter a number:'))
if num % 2==0:
evenlist.append(num)

print('even number list:',evenlist)


=====================================================
#dictationary
student={'name':'sandra','class':11,'fee':20}
print('student=',student)
print('name=',student['name'])
print('class=',student['class'])

student2=['sandra',11,20,'sandra2']
print('student2=',student2)
print('class=',student2[1])

dict1={}
print('dict1=',dict1)
dict1[1]='one'
dict1[2]='two'
dict1[3]='three'

print('dict1=',dict1)
d=dict()
print('d=',d)
d[1]='one'
d[2]='two'
d[3]='three'
print('d=',d)
print('d[1]=',d[1])
print('d[3]=',d[3])

You might also like