Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

PYTHON PROGRAMS

SUM OF NUMBERS
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
# Add two numbers
sum =float (num1) + float(num2)
# Display the sum
print('The sum of{0} and {1} is {2}'.format(num1,num2,sum))

POSITIVE OR NEGATIVE
num=input ("Enter number:")
if num>0:
print num,"is Positive",num
elif num==0:
print "neither negative nor positive"
else :
print num,"negative"
AREA OF TRIANGLE
a=input("enter a") import math
b=input("enetr b") a=input("enter a")
c=input("enter c") b=input("enetr b")
s=(a+b+c)/2 c=input("enter c")
area=(s*(s-a)*(s-b)*(s-c))**0.5 s=(a+b+c)/2
print"Area=",area area=math.sqrt(s*(s-a)*(s-b)*(s-c))
print"Area=",area

LARGEST AMONG THREE NUMBERS


a=input("enter a")
b=input("enetr b")
c=input("enter c")
if a>b:
if a>c:
print a,"is large"
else:
print c,"is large"
elif b>c:
print b,"is large"
else :
print c,"is large"

FACTORIAL OF A NUMBER
n=input("enter a") n=input("enter a")
i=1 f=1
f=1 for i in range(1,n):
while i<=n: f=f*i
f=f*i print "factorial of {0} is
i=i+1 {1}".format(n,f)
print "factorial of {0} is
{1}".format(n,f)

You might also like