What is Linear Search in Python? Linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched. Linear search runs in at worst time and […]

# Python

## Python program to check whether the given number is Even or Odd

So today we are going to write a Python program to check whether the given number is even or odd. Logic: If number is completely divisible by 2 with remainder 0 then it is and even number otherwise the number is odd. As you must be aware ” % ” modulus is used to […]

## Program to swap two numbers in Python

Today we will write a program to swap two numbers in Python, we have two ways to do it: Swap using temporary variable. Swap without using temporary variable. Program to swap two numbers in Python using temporary variable:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
a = 10 b = 20 print("before swapping\na=", a, " b=", b) temp = a a = b b = temp print("\nafter swapping\na=", a, " b=", b) |

OUTPUT:

1 2 3 4 5 6 7 8 9 |
before swapping a= 10 b= 20 after swapping a= 20 b= 10 |

Program to swap two numbers in Python without using temporary variable: Method […]

## Program to find largest among three numbers in Python

Today we are going the write one of the simplest program in Python to find largest among three numbers. Here, we will input three numbers and our program will find the largest of them all. Program to find largest among three numbers in Python:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
print("enter three numbers:") a = int(input()) b = int(input()) c = int(input()) if a>b and a>c: print(a, " is largest") elif b>a and b>c: print(b, " is largest") else: print(c, " is largest") |

OUTPUT:

1 2 3 4 5 6 7 8 9 |
enter three numbers: 9 2 12 12 is largest |

That’s our quick program, need […]