0% found this document useful (0 votes)
6 views

Basic python programs

Basic python program

Uploaded by

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

Basic python programs

Basic python program

Uploaded by

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

Basic python programs:

4. Calculate simple interest


1. Addition of two numbers Output
Output p=int(input(“enter principle
a=int(input(“enter first no”)) amount”))
b=int(input(“enter second no”)) n=int(input(“enter no of years”))
c=a+b r=int(input(“enter rate of
print(“the sum is “,c) interest”))
si=p*n*r/100
OUTPUT: print(“simple interest is”,si)
enter first no OUTPUT:
5 enter principle amount 5000
enter second no enter no of years 4
6 enter rate of interest6
the sum is 11 simple interest is 1200.0

2. Area of rectangle Output 5. Calculate engineering


l=int(input(“enter the length of cutoff Output
rectangle”)) p=int(input(“enter physics
b=int(input(“enter the breath of marks”))
rectangle”)) c=int(input(“enter chemistry
a=l*b marks”))
print(a) m=int(input(“enter maths
OUTPUT: marks”))
enter the length of rectangle 5 cutoff=(p/4+c/4+m/2)
enter the breath of rectangle 6 print(“cutoff =”,cutoff)
30 OUTPUT:
enter physics marks 100
3. Area & circumference of enter chemistry marks 99
circle output enter maths marks 96
r=int(input (“enter the radius of cutoff = 97.75
circle”))
a=3.14*r*r 6. Check voting eligibility
c=2*3.14*r output
print(“the area of circle”,a) age=int(input(“enter ur age”))
print(“the circumference of If(age>=18):
circle”,c) print(“eligible for voting”)
OUTPUT: else:
enter the radius of circle4 print(“not eligible for
the area of circle 50.24 voting”)
the circumference of circle OUTPUT:
25.12 Enter ur age
19 9. Print n odd numbers
Eligible for voting Output
for i in range(1,10,2):
print(i)
OUTPUT:
7. Find greatest of three
13579
numbers output
a=int(input(“enter the value of
10. Print n even
a”))
numbers Output
b=int(input(“enter the value of
b”))
for i in range(2,10,2):
c=int(input(“enter the value of c”))
print(i)
if(a>b):
OUTPUT:
if(a>c):
2468
print(“the greatest no
is”,a)
11. Print squares of
else:
numbers Output
print(“the greatest no
is”,c)
for i in range(1,5,1):
else:
print(i*i)
if(b>c):
OUTPUT:
print(“the greatest no
1 4 9 16
is”,b)
else:
12. Print squares of
print(“the greatest no
numbers Output
is”,c)
OUTPUT:
for i in range(1,5,1):
enter the value of a 9
print(i*i*i)
enter the value of a 1
OUTPUT:
enter the value of a 8
1 8 27 64
the greatest no is 9
13. Print n natural
numbers Output
Programs on for loop i=1
while(i<=5):
8. Print n natural numbers print(i)
Output i=i+1
for i in range(1,5,1): OUTPUT:
print(i) 1
2
OUTPUT: 3
1234 4
5 25

17. Print n cubes


14. Print n odd numbers numbers Output
Output i=1
i=2 while(i<=3):
while(i<=10): print(i*i*i)
print(i) i=i+1
i=i+2 OUTPUT:
OUTPUT: 1
2 8
4 27
6
8 18. find sum of n
10 numbers Output
i=1
15. Print n even sum=0
numbers Output while(i<=10):
i=1 sum=sum+i
while(i<=10): i=i+1
print(i) print(sum)
i=i+2 OUTPUT:
OUTPUT: 55
1
3 19. factorial of n
5 numbers/product of n
7 numbers Output
9 i=1
product=1
16. Print n squares of while(i<=10):
numbers Output product=product*i
i=1 i=i+1
while(i<=5): print(product)
print(i*i)
i=i+1 OUTPUT:
OUTPUT: 3628800
1
4
9
16
20. sum of n numbers c=a
Output a=b
def add(): b=c
a=int(input(“enter a print("a=",a,"b=",b)
value”)) swap()
b=int(input(“enter b OUTPUT:
value”)) enter a value3
c=a+b enter b value5
print(“the sum is”,c) a= 5 b= 3
add()
OUTPUT:
enter a value
23. check the no
6
divisible by 5 or not
enter b value
Output
4
def div():
the sum is 10
n=int(input("enter n
21. area of rectangle
value"))
using function Output
if(n%5==0):
def area():
print("the number is
l=int(input(“enter the length
divisible by 5")
of rectangle”))
else:
b=int(input(“enter the
print("the number not
breath of rectangle”))
divisible by 5")
a=l*b
div()
print(“the area of rectangle
OUTPUT:
is”,a)
enter n value10
area()
the number is divisible by
OUTPUT:
5
enter the length of
rectangle 20
24. find reminder and
enter the breath of
quotient of given no
rectangle 5
Output
the area of rectangle is
def reminder():
100
a=int(input("enter a"))
b=int(input("enter b"))
22. swap two values of
R=a%b
variables Output
print("the reminder is",R)
def swap():
def quotient():
a=int(input("enter a
a=int(input("enter a"))
value"))
b=int(input("enter b"))
b=int(input("enter b
Q=a/b
value"))
print("the reminder is",Q)
reminder()
quotient()
OUTPUT:
enter a 6
enter b 3
the reminder is 0
enter a 8
enter b 4
the reminder is 2.0
25. convert the 26. program for basic
temperature Output calculator Output
defctof(): def add():
c=int(input("enter a=int(input("enter a
temperature in value"))
centigrade")) b=int(input("enter b
f=(1.8*c)+32 value"))
print("the temperature in c=a+b
Fahrenheit is",f) print("the sum is",c)
defftoc(): def sub():
f=int(input("enter temp in a=int(input("enter a
Fahrenheit")) value"))
c=(f-32)/1.8 b=int(input("enter b
print("the temperature in value"))
centigrade is",c) c=a-b
ctof() print("the diff is",c)
ftoc() defmul():
OUTPUT: a=int(input("enter a
enter temperature in value"))
centigrade 37 b=int(input("enter b
the temperature in value"))
Fahrenheit is 98.6 c=a*b
enter temp in Fahrenheit print("the mulis",c)
100 def div():
the temperature in a=int(input("enter a
centigrade is 37.77 value"))
b=int(input("enter b
value"))
c=a/b
print("the div is",c)
add()
sub()
mul()
div()
OUTPUT:
enter a value 10
enter b value 10
the sum is 20
enter a value 10
enter b value 10
the diff is 0
enter a value 10
enter b value 10
the mul is 100
enter a value 10
enter b value 10
the div is 1

You might also like