Determine whether a number is available in the list

In this python if else program, we will determine whether a given number is available in the list.

The most convenient way to check whether the list contains the element is using the in operator.

Steps to solve the program
  1. Take a list of a random numbers of your choices.
  2. Take a number as input through the user.
  3. Using if-else statement check whether the input number is available in the given list or not.
  4. Print the respective output.
				
					list1 = [22,33,49,34,65,67,12,25]
num = int(input("Enter a number: "))

if num in list1:
    print(f"{num} is available in the list")
else:
    print(f"{num} is not available in the list")
				
			

Output :

				
					Enter a number: 65
65 is available in the list
				
			

Related Articles

describe the interview process.

find the largest number among three numbers.

Python nested If else program to describe the interview process

In this Python nested if-else program, we will describe the interview process depending on the round cleared by the applicant. The interview process consists of multiple rounds. If the candidate clears the first round then only he/she will move to the second round otherwise he/she will be removed from the process.


Hint:
Use nested if-else statements.

Steps to solve the program
  1. Take two variables input from user round1 and round2 and assign the interview result as passed or failed.

  2. If condition checks, if round1 is passed then the candidate, can appear for round2. If  round2 is also passed then the candidate will be considered as placed.

  3. If a candidate failed in the first round1 then he can not appear for round2.
				
					round1 = input("Enter round1 result:")
round2 = input("Enter round2 result:")

if round1 == "passed":
    print("Congrats your 1st round is clear")
    if round2 == "passed":
        print("Congrats 2nd round is clear, you are placed")
    else:
        print("Failed in 2nd round, please try next time")
else:
    print("Failed in 1st round, please try next time")

				
			

Output :

				
					Enter round1 result :passed
Enter round2 result :failed

Congrats your 1st round is clear
Failed in 2nd round, please try next time
				
			
				
					Enter round1 result :passed
Enter round2 result :passed

Congrats your 1st round is clear
Congrats 2nd round is clear, you are placed
				
			
				
					Enter round1 result :failed
Enter round2 result :failed

Failed in 1st round, please try next time
				
			

Related Articles

print a square or cube if the given number is divided by 2 or 3 respectively.

determine whether a given number is available in the list 

Print a square or cube of the given number

In this python if else program, we will print a square or cube if the given number is divided by 2 or 3 respectively.

To find the square of a number we need to multiply that number by itself.
To find the cube of a number we need to multiply that number by itself 3 times.

Steps to solve the program
  1. Take a number as input through the user.
  2. If the number is divided by 2 then print its square.
  3. If the number is divided by 3 then print its square.
  4. Use if-else statement for this purpose.
  5. Print square or cube.
				
					# Take input through the user
num = int(input("Enter a number: "))
# Check for division
# If divisible by 2 then print square
# If divisible by 3 then print cube
if num%2 == 0:
# Print output
    print("Sqaure: ",num**2)
elif num%3 == 0:
# Print output
    print("Cube: ",num**3)
				
			

Output :

				
					Enter a number: 9
Cube:  729
				
			

Related Articles

validate user_id in the list of user_ids.

describe the interview process.

Python program to validate user_id in the list of user_ids.

In this python if else program, we will validate user_id in the list of user_ids. Take a user id to validate user_id.

Steps to solve the program
  1. Take a list of user ids and take a user id as input through the user.
  2. Check whether the input id is in the list of user ids or not using an if-else statement.
  3. Print the respective output.
				
					# List of user ids
id_list = [1,2,3,5,6,7,8]
# Take user id as input through the user
id_ = int(input("Enter ID number: "))
# Check whether input id is in list of ids
if id_ in id_list:
# Print output
    print("Valid ID")
else:
# Print output
    print("Invalid ID")
				
			

Output :

				
					Enter ID number: 5
Valid ID
				
			

Related Articles

check authentication with the given username and password.

print a square or cube if the given number is divided by 2 or 3 respectively.

Program to check the authentication of username and password

In this python if else program, we will check authentication of username and password. The name and password of the user should be the same to be valid

Steps to solve the program
  1. Take Username and password as input through the user.
  2. If the username and password is equal then it is authenticate.
  3. Use if-else statement for this purpose.
  4. Print the output.
				
					# Take username and password as input through the user
name = input("Enter name: ")
password = input("Enter password: ")
# Authenticate username and password
if name == password:
# Print output
    print("It is valid")
else:
# Print output
    print("It is not valid")
				
			

Output :

				
					Enter name: sanket
Enter password: 1234
It is not valid
				
			

Related Articles

check a given number is part of the Fibonacci series from 1 to 10.

validate user_id in the list of user_ids.

Check a number is part of the Fibonacci series

In this python if else program, we wiil check a given number is part of the Fibonacci series or not.

What is Fibonacci series?
The Fibonacci sequence is a set of integers (the Fibonacci numbers) that starts with a zero, followed by a one, then by another one, and then by a series of steadily increasing numbers.

Steps to solve the program
  1. Take a list of all the numbers in a Fibonacci series from 0-10.
  2. Take a number as input through the user.
  3. Use if-else statement to check whether the given number is a part of the Fibonacci series or not.
  4. Print the output.
				
					# Fibonacci series
fib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
# Take input through the user
num = int(input("Enter a number: "))
# Check for number in fibonacci series
if num in fib:
# Print output
    print("It is a part of the series")
else:
# Print output
    print("It is not a part of the series")
				
			

Output :

				
					Enter a number: 22
It is not a part of the series
				
			

Related Articles

check given number is odd or even.

check authentication with the given username and password.

Python program to check given number is odd or even.

In this python if else program, we will check whether the given number is odd or even.

Odd number:
Odd numbers are those numbers that cannot be divided into two equal parts.


Even number:
even numbers are those numbers that can be divided into two equal parts.

Steps to solve the program
  1. Take the number as input through the user.
  2. Using an if-else statement check whether the given number is odd or even.
  3. If the number is divisible by 2 then it is even else odd.
  4. Print respective output.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Check for odd and even number
if num%2 == 0:
# Print output
    print("It is an even number")
else:
#Print output
    print("It is an odd number")
				
			

Output :

				
					Enter a number: 23
It is an odd number
				
			

Related Articles

check given number is a prime number or not.

check a given number is part of the Fibonacci series from 1 to 10.

Program to check whether the number is a prime number.

In this python if else program, we will check whether an number is a prime number or not.

A prime number is a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1.

Hint:
Use for loop with the range function and use if statement inside the loop

Steps to solve the program
  1. Take a number as input through the user and create a variable count and assign its value equal to 0.
  2. Use for loop with the range function to iterate over 2 to the given number.
  3. During the iteration check if any number divided the given number then add 1 to the count variable using if-else statement.
  4. If value of the count variable is greater then 0 then it is not a prime number.
  5. Print the respective output.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Create count variable
count = 0
# Iterate over numbers
for i in range(2,num):
# Check for division
    if num%i == 0:
    # Add 1 to the count variable
        count += 1
# Check for prime number        
if count > 0:
# Print output
    print("It is not a prime number")
else:
#Print output
    print("It is a prime number")
				
			

Output :

				
					Enter a number: 59
It is a prime number
				
			

Related Articles

print the square of the number if it is divided by 11.

check given number is odd or even.

Python program to print the square of the number

In this python if else program, we will print the square of the number if it is divided by a certain number ( 11 ). To find the square of a number we need to multiply that number by itself or we can use power operator to get square of the value. e.g. var1**2

Hint:
Use ** to get the square.

Steps to solve the program
  1. Take a number as input through the user.
  2. Use an if-else statement to check whether the given number is divisible by 11 or not.
  3. If yes then print its square.
  4. Else print False.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Check for division
if num%11 == 0:
    # Print output
    print(num**2)
else:
    # Print output
    print("Number is not divisible by 11")
				
			

Output :

				
					Enter a number: 22
484
				
			
				
					Enter a number: 31
Number is not divisible by 11
				
			

Related Articles

check the given number divided by 3 and 5.

check given number is a prime number or not.

Python program to check number is divided by 3 and 5

In this, if else program, we will check whether the given number is divided by 3 and 5 or not. 

Hint:
Use AND(&) with if-else statement.

Steps to solve the program
  1. Take a number as input through the user.
  2. Use if-else statements to check whether the given number is divisible by 3 and 5 also.
  3. If yes then then print True, if not then print False.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Check for division
if num%3 == 0  and num%5 == 0:
    # Print output
    print("Given number can divide by both 3 and 5")
else:
    # Print output
    print("Given number can not divide by 3 and 5")
				
			

Output : 

				
					Enter a number: 6
Given number can not divide by 3 and 5
				
			
				
					Enter a number: 15
Given number can divide by both 3 and 5
				
			

Related Articles

assign grades as per total marks.

print the square of the number if it is divided by 11.