Blog

Basic program in Python - Bharosewale

Posted By naveen singh on 31 Jan 2023

python-program

List of Basic Python Programs

 

Program in Python to print "Hello World ! ".

 

print("Hello World !”)   # print() function का प्रयोग हम output,message और value provides करने के लिए करते हैं, message को  हमेशा  हम single या double quotes के अंदर print करते हैं और value को हम single या double quotes में print नहीं  करते हैं |

 

 

 Program in Python to do arithmetic operations.

 

# पहले variable में value assign करना |

a = 2 

# दूसरे variable में value assign करना |

b = 4 

# दो numbers का addition प्रिंट करना |

print("sum of  two numbers:", a+b)

# दो numbers का subtraction प्रिंट करना |

print("subtraction of two numbers:",a-b)

# दो numbers का multiplication प्रिंट करना|

print("multiplication of two  numbers:",a*b)

# दो numbers का division प्रिंट करना |

print("division of two  numbers:",a/b)

# दो numbers का Modulus/Remainder प्रिंट करना |

print("modulus of two numbers:",a%b)

 

 

Program in Python to find the area of a triangle.

 

b= 4        # triangle का base

h=2        # triangle की height

a= 0.5*b*h    # triangle का area (a=1/2 x base x height)

print(“area of a triangle:”,a)

 

 

 Program in Python to solve quadratic equation.

 

a=2   # पहले variable में value assign करना |

b=4   # दूसरे variable में value assign करना |

c=1    # तीसरे variable में value assign करना |

# a,b,c quadratic equation के  coefficient है |

d= (b**2)-4*a*c # quadratic equation का discrimenant निकालना (d=b2-4ac)

print("discriminant:",d)

 

 

Program in Python to swap to variables.              

 

a= 5          #  पहले variable में value assign करना |

b= 4         # दूसरे variable में value assign करना |

a= a+b      #   5 + 4 = 9 , जहां पर a  की value 9 है|

b= a-b      #    9 - 4 = 5 , जहां पर b  की value 5 है |

a= a-b      #   9 - 5 = 4, जहां पर a  की value 4 है |

print("value of a:",a)        

print("value of b:",b)

 

 

 Program in Python to swap to variables using third variable.

 

a= 5

b= 4

c= 0

c= a          #  जहां पर c की  value 5 है |

b= b+c    # जहां पर b की  value 9 है|

a= b-c      # जहां पर a की  value 4 है| 

b= b-a     #  जहां पर b की  value 5 है |

print(“value of a:”,a)

print(“value of b:”,b)

 

 

 Program in Python to find area of a rectangle.

 

L= 4         # जहां L rectangle की  length है |

b= 3       # जहां b rectangle की breadth है |

a= l*b      # जहां a rectangle का area है |

print(“area of a rectangle:”,a)

 

 

Program in Python to calclulate simple interest(SI) of a given principle, rate and time. where principle=1000 , rate= 5, time= 10sec

 

p= 1000    

r= 5

t= 10

SI = (p*r*t)/100 

print(“simple interest:”,SI)   # Simple Interest(SI)=(pxrxt)/100

 

 

Program in Python to calculate Compound Interest(CI).where p=100,r=6,n=2  

 

p= 100

r= 6

n= 2

CI= p*(1+r/100)**n

print(“compound interest:”,CI)     # Compound Interest(SI)= p*(1+r/100)n

 

 

 Program in Python to calculate Annual Interest(AI).where p=100,r=4,n=2

 

p= 1000

r= 4

n= 3

AI= p*(1+r//100)**n-p

print(“compound interest:”,AI)    # Annual Interest(AI)= p*(1+r//100)n -p

         

 

Program in Python to calculate sum and average of five marks of a  student.

 

avg=0

sum=0       

m1=20  # first marks

m2=30   # second marks    

m3=40   # third marks

m4=50 # fourth marks

m5=60   # fifth marks

sum= m1+m2+m3+m4+m5

avg=sum/5

print(“sum:”,sum)       # print sum of five marks

print(“average:”,avg) # print average of five marks

 

Comments


Manish pandey

Very useful content about list in python

05/04/2023

Kritika

Thank you for sharing it..

15/02/2023