Python Basic Programs

Define Python :-

            Python is an interpreted, object-oriented programming language similar to PERL, that has gained popularity because of its clear syntax and readability. Python is said to be relatively easy to learn and portable, meaning its statements can be interpreted in a number of operating systems, including UNIX-based systems, Mac OS, MS-DOS, OS/2, and various versions of Microsoft Windows 98. Python was created by Guido van Rossum, a former resident of the Netherlands, whose favorite comedy group at the time was Monty Python's Flying Circus. The source code is freely available and open for modification and reuse.


Image result for python  
 Basic Logic python programs...
  • Armstrong Number 
  • Check Leap Year
  • Check Prime Number
  • Factorial Of a Number
  • Fibanacci Series
  • Make Simple Calculator
  • State Of a Number
  • Swap Two Variables

Armstrong Number :             

def prime_number(n):
    value=0    for i in range(2,int(n/2)):
        if(n%i==0):
            value=1
    if(value==1):
        print("It not a is prime number")
    else:
        print("It is a prime number")

x=int(input("Enter the number : "))
prime_number(x)

Check Leap Year :

def leap_year_evaluate(x):
    if(x%4==0):
        print("It is leap year")

    else:
        print("It is not leap year")

n=int(input("Enter the year :"))
leap_year_evaluate(n)

Check Prime Number :

def check_prime_number(n):
    for i in range (2,n-1):
        temp=n
        if(temp%i==0):
            temp%=i

    if(temp==n):
        print("\nIt is prime number")
    else:
        print("\nIt is not a prime number")



x=int(input("Enter the number"))
check_prime_number(x)

Swap Tow Values :

def swap(x,y):
    temp=x
    x=y
    y=temp
    print("After swap",x,y)

a=int(input(""))
b=int(input(""))
print("Before Swap",a,b)
swap(a,b)


Factorial of a Number :


def factorial(n):
    factorial=1
    if(n>0):
        for i in range(1,n):
            factorial*=i
    elif(n==0):
        factorial=1    else:
        print("No factorial for negative value")

    print(factorial)

x=int(input("Enter the number"))
factorial(x)

Make Simple Calculator :

def addition(a,b):
    print(a+b)


def subraction(a,b):
    print(a-b)


def multiplication(a,b):
    print(a*b)


def division(a,b):
    print(a/b)


x=int(input("\nEnter the number"))
y=int(input("\nEnter the number"))

print("1.Addition\n2.Subraction\n3.Multiplication\n4.Division\n")
z=int(input("Enter your choice :"))
if(z==1):
    addition(x,y)


elif(z==2):
    subraction(x,y)


elif(z==3):
    multiplication(x,y)


elif(z==4):
    division(x,y)

else:
    print("Try other")

State of a Number :

def evaluate(x):
    if(x<0):
        print("Number is negative")
    elif(x==0):
        print("Number is Zero")
    else:
        print("Number is positive")


a=int(input("Enter the number"))
evaluate(a)

Fibanacci Series :

def fibanacci_series(x):
    a=0    b=1    print(a,b)
    for i in range(1,x):
        next=a+b
        a=b
        b=next
        print(next)

n=int(input("Enter the number"))
fibanacci_series(n)

To download the Zip file of  Basic Programs : Click Here














Post a Comment

0 Comments