Advanced Exercises: Control Flow

  1. Palindrome Checker:

    Write a Python program that takes a string as input and checks if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward.

                    Input: "radar"
                    Output: It is a palindrome.
    
                    Input: "python"
                    Output: It is not a palindrome.
                
  2. Prime Number Checker:

    Write a Python program that takes an integer as input and checks if it is a prime number. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.

                    Input: 7
                    Output: It is a prime number.
    
                    Input: 12
                    Output: It is not a prime number.
                
  3. Pattern Printing:

    Write a Python program to print the following pattern using loops:

                    Output:
                    *
                    **
                    ***
                    ****
                    *****
                
  4. Fibonacci Sequence:

    Write a Python program to generate the first n terms of the Fibonacci sequence using a while loop. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.

                    Input: n = 8
                    Output: 0, 1, 1, 2, 3, 5, 8, 13
                
  5. Leap Year Checker:

    Write a Python program that takes a year as input and checks if it is a leap year. A leap year is divisible by 4 but not by 100 unless it is also divisible by 400.

                    Input: 2020
                    Output: It is a leap year.
    
                    Input: 1900
                    Output: It is not a leap year.
    
                    Input: 2000
                    Output: It is a leap year.
                

Control Flow (if, else, for, while) YouTube Video