Brainstorming 02: For and While Loops

Questions are based on For and While Loops :

  1.  Sum of Even Numbers
    Write a Python program to calculate the sum of all even numbers between 1 and 100 using a for loop.

  2.  Simple Number Guessing Game
    Create a number guessing game where the user has to guess a number between 1 and 10. Use a while loop to give the user multiple attempts, and provide hints if the guess is too high or too low.

  3.  Count Vowels in a String
    Write a program that takes a string input from the user and counts the number of vowels in the string using a for loop and an if statement.

  4.  Print a Multiplication Table
    Write a Python program that prints the multiplication table of a given number (up to 10). Use a for loop to display the table.

  5.  Check for Prime Number
    Write a Python program to check if a given number is prime or not using a for loop and conditional statements.

  6.  Find the Factorial of a Number
    Write a Python program to find the factorial of a number using a while loop. Make sure to validate the input and handle negative numbers appropriately.

  7.  FizzBuzz
    Implement the classic FizzBuzz problem using a for loop. Print numbers from 1 to 50, but for multiples of 3 print "Fizz" instead of the number, and for multiples of 5 print "Buzz". For numbers that are multiples of both 3 and 5, print "FizzBuzz".

  8.  Sum of Digits in a Number
    Write a Python program to find the sum of digits of a number using a while loop and conditional statements.

  9.  Palindrome Check
    Write a Python program that checks whether a given string is a palindrome or not using a while loop and conditional statements.

  10.  Calculate the GCD of Two Numbers
    Write a program to calculate the Greatest Common Divisor (GCD) of two numbers using a while loop and the Euclidean algorithm.

  11.  Find Armstrong Numbers
    Write a Python program to find all Armstrong numbers between 100 and 1000 using a for loop and conditional statements. An Armstrong number is one that equals the sum of its digits each raised to the power of the number of digits.

  12.  Generate Fibonacci Sequence
    Write a Python program to generate the first n terms of the Fibonacci sequence using a while loop. Ensure that n is provided by the user.

  13.  Calculate Exponent Without Using the ** Operator
    Write a Python program that calculates the value of x raised to the power y using a for loop and multiplication (without using the ** operator).

Previous Post Next Post