de

PYTHON PROGRAMS


PRINT Hello World

print("Hello World")

ADD TWO NUMBERS

a=5

b=6

c=a+b

print c

INPUT TWO NUMBERS AND FIND ITS PRODUCT


a=input("Enter the first number")

b=input("Enter the second number")

c=a*b

print (c)

FIND ODD OR EVEN

a=input("enter the number")

if (a%2==0):

  print("the number is even")

else:

  print("the number is odd")

FIND FIRST N NATURAL NUMBERS

a=input("enter the limit")

for i in range (1,a):

  print i

PRIME NUMBER

n=input("enter the number")

a=n/2

flag=1

for i in range (2,a+1):

  if (n%i==0):

    flag=0

if (flag==0):

  print("not a prime")

else:

  print("prime")

 

FIRST N PRIME NUMBERS

m=input("enter the limit")

for j in range(2,m):

  n=j

  flag=1

  for i in range(2,n):

    if (n%1==0):

      flag=0

  if (flag==1):

    print n

FACTORIAL

a=input("enter a number")

fact=1

for i in range(1,a+1):

  fact=fact*i

print 'factorial is',fact