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

PROGRAM

The document contains 12 Python programs with explanations and outputs. The programs cover topics like factorial, maximum number, patterns, volume and area calculations, simple and compound interest, and a basic calculator program using functions.

Uploaded by

anuchaitanya2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

PROGRAM

The document contains 12 Python programs with explanations and outputs. The programs cover topics like factorial, maximum number, patterns, volume and area calculations, simple and compound interest, and a basic calculator program using functions.

Uploaded by

anuchaitanya2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1 #PROGRAM TO FACTORIAL OF NUMBER USING WHILE LOOP

n=int(input("enter real number:"))


fact=1
a=1
while a<=n:
fact*=a
a+=1
print("fact=",fact)

#OUTPUT
====== RESTART: /Users/chaitanya/Desktop/py/factorial using while
loop.py ======
enter real number:10
fact= 3628800

2 #PROGRAM TO FIND MAXIMUM NUMBER.

a=int(input("enter a no-"))
b=int(input("enter a no-"))
c=int(input("enter a no-"))

if a>b and a>C:


print(a,"is maximum no.")
elif b>a and b>c:
print(b,"is maximum no.")
else:
print(c,"is maximum no.")

#OUTPUT
================ RESTART: /Users/chaitanya/Desktop/py/maximum.py
===============
enter a no-2
enter a no-4
enter a no-6
6 is maximum no.

3 #PROGRAM TO PRINT DECREASING TRIANGLE PATTERN

n=int(input("Enter the no. of rows"))


for i in range(n+1,0,-1):
for j in range(i,1,-1):
print("*",end="")
print()

#OUTPUT
=============== RESTART: /Users/chaitanya/Desktop/py/pattern 2.py
==============
Enter the no. of rows4
****
***
**
*
4 # PROGRAM TO PRINT SQUARE PATTERN

n=int(input('Enter the number of rows:-'))

for i in range(0,n):
for j in range(1,n+1):
print('*',end="")
print()

#OUTPUT
=============== RESTART: /Users/chaitanya/Desktop/py/pattern 3.py
==============
Enter the number of rows:-5
*****
*****
*****
*****
*****

5 #PROGRAM TO PRINT HILL PATTERN


n=int(input("Enter the no.of rows"))

for i in range(0,n):
for j in range(n-i):
print('',end='')
for j in range(i,2*i+1):
print('*',end='')
for j in range(1,i+1):
print('*',end='')
print()

#OUTPUT
=============== RESTART: /Users/chaitanya/Desktop/py/pattern 4.py
==============
Enter the no.of rows5
*
***
*****
*******
*********

6 # PROGRAM TO FIND THE SUM EVEN AND ODD ITEGERS OF 1ST NATURAL
NUMBER.

n=int(input("enter the any positive real number"))


esum=osum=0
for a in range(1,1+n):
if a%2==0:
esum=esum+a
else:
osum=osum+a
print("even sum:",esum,"odd sum:",osum)
#OUTPUT
====== RESTART: /Users/chaitanya/Desktop/py/sum of even and odd
number.py ======
enter the any positive real number5
even sum: 6 odd sum: 9

7 # PROGRAM TO FIND VOLUME ,CURVED SURFACE AREA AND TOTAL SUFRACE


AREA OF CYLINDR

from math import pi


r=float(input("Enter the radius"))
h=float(input("Enter the height"))
print("For volume press 1","For C_surface press 2","For T_surface
press 3")
a=int(input("Enter what you want to do:-"))
if a==1:
print("Finding volume of cylinder",pi*(r**2)*h)
elif a==2:
print("Finding Curved surface area",2*pi*r*h)
elif a==3:
print("Finding Total surface area",(2*pi*r*h)+(2*pi*(r**2)))
else:
print("invalid choice")

#OUTPUT

= RESTART: /Users/chaitanya/Desktop/py/volume ,curved and total of


cyllinder.py
Enter the radius5
Enter the height5
For volume press 1 For C_surface press 2 For T_surface press 3
Enter what you want to do:-1
Finding volume of cylinder 392.69908169872417

= RESTART: /Users/chaitanya/Desktop/py/volume ,curved and total of


cyllinder.py
Enter the radius3
Enter the height5
For volume press 1 For C_surface press 2 For T_surface press 3
Enter what you want to do:-3
Finding Total surface area 150.79644737231007

= RESTART: /Users/chaitanya/Desktop/py/volume ,curved and total of


cyllinder.py
Enter the radius3
Enter the height4
For volume press 1 For C_surface press 2 For T_surface press 3
Enter what you want to do:-2
Finding Curved surface area 75.39822368615503
8 # PROGRAM TO FIND VOLUME ,CURVED SUREFACE AREA AND TOTAL SURFACE
AREA OF CUBE

def volume ():


vol=a**3
return vol
def Curved_area():
C_area=4*(a**2)
return C_area
def Total_area():
T_area=6*(a**2)
return T_area

print("For volume press 1, For Curved surface area press 2, For


Total surface area press 3")
n=int(input("What you want to find out:-"))
a=float(input("Enter the length"))

if n==1:
print("Finding volume of cube",volume())
elif n==2:
print("Finding curved surface area",Curved_area())
elif n==3:
print("Finding Total surface area",Total_area())
else:
print("Invalid choice")

#OUTPUT

======== RESTART: /Users/chaitanya/Desktop/py/volume and area of


cube.py =======
For volume press 1, For Curved surface area press 2, For Total
surface area press 3
What you want to find out:-1
Enter the length3
Finding volume of cube 27.0

======== RESTART: /Users/chaitanya/Desktop/py/volume and area of


cube.py =======
For volume press 1, For Curved surface area press 2, For Total
surface area press 3
What you want to find out:-2
Enter the length3
Finding curved surface area 36.0

======== RESTART: /Users/chaitanya/Desktop/py/volume and area of


cube.py =======
For volume press 1, For Curved surface area press 2, For Total
surface area press 3
What you want to find out:-3
Enter the length3
Finding Total surface area 54.0
9 #PROGRAM TO FINND THE SQUARE OF A NO PROGRESSIVELY

n=int(input("enter the number:"))


a=1
while a<=n:
print("square of number",a,"=",a*a)
a+=1

#OUTPUT

===== RESTART: /Users/chaitanya/Desktop/py/square of a no


progressively.py =====
enter the number:10
square of number 1 = 1
square of number 2 = 4
square of number 3 = 9
square of number 4 = 16
square of number 5 = 25

10 # program to find area of sphere

from math import pi


r=float(input("Enter the radius"))
area=4*pi*(r**2)
volume=4/3*pi*(r**3)
print("AREA",area)
print("VOLUME",volume)

#OUTPUT
======= RESTART: /Users/chaitanya/Desktop/py/volume and area of
sphere.py ======
Enter the radius4
AREA 201.06192982974676
VOLUME 268.082573106329

11 # PROGRAM TO FIND SIMPLE INTREST AND COMPOUND INTREST

p=int(input("Enter the principle:-"))


t=float(input("Enter the time (in years):-"))
r=float(input("Enter the rate of intrest(in percentage):-"))
print("For S.I. press 1","For C.I. press 2")
a=int(input("What you want to perform:-"))
if a==1:
print(" S.I.:-",p*r*t//100)
if a==2:
A=p*(1+(r/100))**t
print(" C.I.:-",A-p)

#OUTPUT

=============== RESTART: /Users/chaitanya/Desktop/py/SI andCI.py


===============
Enter the principle:-10000
Enter the time (in years):-2
Enter the rate of intrest(in percentage):-10
For S.I. press 1 For C.I. press 2
What you want to perform:-1
S.I.:- 2000.0

=============== RESTART: /Users/chaitanya/Desktop/py/SI andCI.py


===============
Enter the principle:-10000
Enter the time (in years):-2
Enter the rate of intrest(in percentage):-10
For S.I. press 1 For C.I. press 2
What you want to perform:-2
C.I.:- 2100.000000000002

12 # PROGRAM TO FORM CALCULATOR USING FUNCTION


import math

def Add(a,b):
Sum=a+b
return Sum
def Subtract(a,b):
difference=a-b
return difference
def Multiply(a,b):
product=a*b
return product
def Divide(a,b):
quotient=a/b
return quotient
def squ(a):
sqre=a**2
sqre=b**2
return sqre
def sqrot(a):
sqroot= math.sqrt(a)
sqrout= math.sqrt(b)
return sqroot
n1=int(input("Enter the value"))
n2=int(input("Enter the value"))
print("For add press 1","For subtract press 2","For multiply press
3","For divide press 4","For square press 5","For square root press
6")
a=int(input("Enter what you want to do:-"))
if a==1:
print("Sum of the numbers",Add(n1,n2))
elif a==2:
print("difference of the numbers",Subtract(n1,n2))
elif a==3:
print("product of the numbers",Multiply(n1,n2))
elif a==4:
print("Dividing of the numbers",Divide(n1,n2))
elif a==5:
print("Finding the Square n1",n1**2)
print("Finding the Square n2",n2**2)
elif a==6:
print("The square root of the number is:-",sqrot(n1))
print("The square root of the number is:-",sqrot(n2))
else:
print("invalid choice")

# OUTPUT

========= RESTART: /Users/chaitanya/Desktop/py/


Calculator( function).py ========
Enter the value 10
Enter the value10
For add press 1 For subtract press 2 For multiply press 3 For divide
press 4 For square press 5 For square root press 6
Enter what you want to do:-1
Sum of the numbers 20

========= RESTART: /Users/chaitanya/Desktop/py/


Calculator( function).py ========
Enter the value10
Enter the value10
For add press 1 For subtract press 2 For multiply press 3 For divide
press 4 For square press 5 For square root press 6
Enter what you want to do:-3
product of the numbers 100

========= RESTART: /Users/chaitanya/Desktop/py/


Calculator( function).py ========
Enter the value10
Enter the value10
For add press 1 For subtract press 2 For multiply press 3 For divide
press 4 For square press 5 For square root press 6
Enter what you want to do:-4
Dividing of the numbers 1.0

========= RESTART: /Users/chaitanya/Desktop/py/


Calculator( function).py ========
Enter the value10
Enter the value10
For add press 1 For subtract press 2 For multiply press 3 For divide
press 4 For square press 5 For square root press 6
Enter what you want to do:-5
Finding the Square n1 100
Finding the Square n2 100

You might also like