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 will check whether a given number is part of the Fibonacci series.

What is the 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 :", num)
else:
   # Print output
    print("It is not a part of the series :", num)
				
			

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.

If-else program to assign grades as per total marks

In this python if else program, we will assign grades to each student as per total marks scored.

Condition for grades:
Marks less than 40: Fail
Marks between 40-50: Grade C
Marks between 51-60: Grade B
Marks between 61-70: Grade A
Marks between 71-80: Grade A+
Marks between 81-90: Grade A++
Marks between 91-100: Excellent

Hint:
Use Multiple if-else statements.

Steps to solve the program
  1. Take marks as input through the user.
  2. Using if-else statements assign grades as per the total marks given.
  3. Use the grades given in the question.
  4. Print the output.
				
					# Take marks through the user
marks = int(input("Enter marks: "))
# Assign grades based on marks
if marks<40:
    # marks is less than 40 then print Fail
    print("Fail")
elif marks>=40 and marks>=50:
    # marks is greater than 40 and less than 50 then got C grade.
    print("Grade C")
elif marks>50 and marks<=60:
    #  marks is greater than 50 and less than 60 then got B grade.
    print("Grade B")
elif marks>60 and marks<=70:
    #  marks is greater than 60 and less than 70 then got A grade.
    print("Grade A")
elif marks>70 and marks<=80:
    #  marks is greater than 70 and less than 80 then got A+ grade.
    print("Grade A+")
elif marks>80 and marks<=90:
    #  marks is greater than 80 and less than 90 then got A++ grade.
    print("Grade A++")
elif marks>90 and marks<=100:
    #  marks is greater than 90 and less than 100 then got Excellent grade.
    print("Excellent")
else:
    # marks is greater than 100 than consider as invalid number..
    print("Invalid marks")
				
			

Output :

				
					Enter marks: 62
Grade C
				
			
				
					Enter marks: 30
Fail
				
			
				
					Enter marks: 93
Excellent
				
			
				
					Enter marks: 100
Invalid marks
				
			

Related Articles

get all the numbers divided by 3 from 1 to 30.

check the given number divided by 3 and 5.

Program to get all numbers divided by 3 between 1 to 30

In this Python if else program we will get all numbers within a given range divided by a certain number. It will print all the numbers which are divisible by 3 between 1-30

Hint:
Use for loop with the range function

Steps to solve the program

  1. Use for loop with the range function to iterate over numbers from 1-30.
  2. Using if else statement check whether a  number is divisible by 3 or not.
  3. If it is divisible by 3 then print the number.
				
					# Iterate over numbers from 1-30
for i in range(1,31):
   # check whether number is divisible by 3
    if i%3 == 0:
       # print output
        print(i,end=" ")
    else:
        continue
				
			

Output :

				
					3 6 9 12 15 18 21 24 27 30
				
			

Related Articles

check given number is divided by 3 or not.

assign grades as per total marks.

Program to check if a number is divisible by 3

In this Python if else program we will check if a number is divisible by 3 or not. Print the number divisible by 3.

Divisibility test: The divisibility rule for 3 states that a number is completely divisible by 3 if the sum of its digits is divisible by 3

Steps to solve the programs
  1. Take a number as input through the user.
  2. Check whether that given number is divisible by 3, using an if else statement.
  3. Print the respective output.
				
					num = int(input("Please enter value :"))
if num%3 ==0:
    print("Number is divisible by 3:", num)
else:
    print("Number is not divisible by 3 :", num)
				
			

Output

				
					Please enter value :21
Number is divisible by 3: 21


Please enter value :25
Number is not divisible by 3 : 25
				
			

get all the numbers divided by 3 from 1 to 30.

Related programs

Print the following pattern as shown in ouput.

In this Python Program, we will print the following pattern as shown using Python

Steps to solve the program
				
					char = 97
var1 = 4
var2 = 4

for i1 in range(7):
    if i1 < 4:
        var1 = var1 - 1
        var2 = var2 + 1

        for j1 in range(9):

            if j1 > var1 and j1 < var2:

                print(chr(char), end=" ")
                char += 1
            else:
                print(" ", end=" ")
        print()

        # var1 = var1 - 1
        # var2 = var2 + 1
    else:
        var1 = var1 + 1
        var2 = var2 - 1
        for k in range(9):

            if k > var1 and k < var2:

                print(chr(char), end=" ")
                char += 1
            else:
                print(" ", end=" ")
        print()

				
			

Output :

				
					_________________


        a         
      b c d       
    e f g h i     
  j k l m n o p   
    q r s t u     
      v w x       
        y  
        
_________________
				
			

Print the following pattern