Check whether the given number is positive or not.

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

Positive number:
A positive number is any number greater than zero. Positive number includes natural numbers.

Steps to solve the program
  1. Take a number as input through the user.
  2. If the number is positive then print True, else print False.
  3. Use an if-else statement for this purpose.
  4. Print the output.
				
					num = int(input("Enter a number: "))

if num>0:
    print("True")
else:
    print("False")
				
			

Output :

				
					Enter a number: 20
True
				
			

Related Articles

check whether a student has passed the exam.

check whether the given number is negative or not.

Check whether a student has passed the exam.

In this python if else program, we will check whether a student has passed the exam or not depending on the marks scored by the student.

Condition to pass the test:
If the marks obtained by the student are equal to or greater than 45 then the student has passed the test, otherwise student has failed the test.

Steps to solve the program
  1. Take the marks of the student as input through the user.
  2. Use an if-else statement to determine whether a student has passed the exam or not.
  3. Use the criteria given in the question to determine the outcome.
  4. Print the output.
				
					marks = int(input("Enter marks of a student: "))

if marks>=45:
    print("Pass")
else:
    print("Fail")
				
			

Output :

				
					Enter marks of a student: 50
Pass
				
			

Related Articles

check if any given string is palindrome or not

check whether the given number is positive or not.

Check whether the string is palindrome or not.

In this python if else program, we will program to check if any given string is palindrome or not.

A string is a palindrome if it remains the same from both ends. When you reverse a string, it is same as the original string.

Hint:
Use indexing.

Steps to solve the program
  1. Take a string as input.
  2. Reverse the given string and store the result in another variable.
  3. Compare both strings using an if-else statement.
  4. If both the strings are equal then the string is palindrome, else string is not palinfrome.
  5. Print the respective output.
				
					str1 = 'jaj'
str2 = str1[::-1]

if str1 == str2:
    print("It is a palindrome string")
else:
    print("It is not a palindrome string")
				
			

Output :

				
					It is a palindrome string
				
			

Related Articles

check whether any given number is a palindrome.

check whether a student has passed the exam

Python program to check whether a number is palindrome.

In this python if else program, we will check whether any given number is palindrome number or not. 

A palindrome number is a number that remains the same when digits are reversed. For example, the number 121 is a palindrome number, but 253 is not a palindrome number.

Hint:
Use string.
Use indexing.

Steps to solve the program
  1. Take a number as input.
  2. Reverse the given number and store it in another variable.
  3. Check whether both the numbers are equal or not using an if-else statement.
  4. Print the respective output.
				
					num1 = 121
num2 = str(num1)

if num1 == int(num2[::-1]):
    print("It is a palindrome number")
else:
    print("It is not a palindrome number")
				
			

Output :

				
					It is a palindrome number
				
			

Related Articles

check any person eligible to vote or not

check if any given string is palindrome or not

Program to check whether a person eligible to vote

In this python if else program, we will check whether a person is eligible to vote or not depending on his/her age.

Condition for eligibility:
If the age of a person is greater than 18 then the person is eligible otherwise not.

Steps to solve the program
  1. Take the age of the person as input through the user.
  2. If the age is greater than or equal to 18 then the person is eligible to vote, else the person is not eligible to vote.
  3. Use if-else statement for this purpose.
  4. Print the respective output.
				
					age = int(input("Enter age: "))

if age >= 18:
    print("You are eligible")
else:
    print("You are not eligible")
				
			

Output :

				
					Enter age: 20
You are eligible
				
			

Related Articles

find the largest number among three numbers.

check whether any given number is a palindrome.

Find the largest number among three numbers.

In this Python if-else program, we will find the largest number among three numbers.

Hint:
Use an elif condition to check the number value.

Steps to solve the program

  1. Take 3 numbers as input through the user.
  2. Find the largest number among three numbers using logic and if else statements.
  3. Print the output.
				
					num1 = int(input("Enter 1st number: "))
num2 = int(input("Enter 2nd number: "))
num3 = int(input("Enter 3rd number: "))

if num1 > num2 and num1 > num3:
    print(f"{num1} is the greatest")
elif num2>num1 and num2 > num3:
    print(f"{num2} is the greatest")
elif num3>num1 and num3 > num2:
    print(f"{num3} is the greatest")
else:
    print("No number has greater value")

				
			

Output :

				
					Enter 1st number: 50
Enter 2nd number: 40
Enter 3rd number: 79
79 is the greatest
				
			

Related Articles

determine whether a given number is available in the list

check any person eligible to vote or not

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.