Python program to find prime number and biggest of three numbers

               In this post, 2 different programs are given. One is to find the given number is prime number or not. Other one is to find the biggest number among the three numbers.

Python program to find prime number:

              Prime number is a number which can divide by itself and 1. For eg, 7,11,13….

#As a beginning, get the number from the user.

no = int(input(“Enter a number”))

#create a variable ‘fl’ and set it as false. Where  ‘fl’ is a Boolean variable which takes either ‘True’ or ‘False’ value.

fl = False

#check the number is greater than one, then it goes to the for loop. There, the program checks whether the number is divided by any other number. If yes, it assign the value ‘True’ to fl and come out of the loop.

if no > 1 :

    for i in range(2,no):

        if no % i == 0 :

          fl = True

          break

#The program checks whether the fl value is True or not. If it is true, it prints “no is not a prime number”. Other wise, it prints “no is a prime number”

if fl == True:

     print(no,”is not a prime number”)

else:

     print(no,”is a prime number”)

Executing this program, you will get the following output.

Python program to find biggest of three numbers:

              This program deals with relational and logiacal operators. The input of the program is three numbers. Output is the biggest of three numbers.

#Get the three integers from command prompt.

x = int(input(“Enter the first number”))

x = int(input(“Enter the second number”))

z = int(input(“Enter the third number”))

#check whether x is greater than y,z, then print x is the biggest.  Otherwise, check y is greater than z. if yes, print y is the biggest number. Else, print z is the biggest number.

if x > y and x > z :

    print(“First number is the biggest number”)

elif y > z :

    print(“Second number is the biggest number”)

else :

    print(“Third number is the biggest number “)

 Execute this program. The output is shown below.


These are the simple programs to execute inpython.

No comments:

Post a Comment