Loops

  1. Print First 10 natural numbers using while loop.

  2. Calculate the sum of all numbers from 1 to a given number.

  3. Write a program to print multiplication table of a given number. eg if number is 2, then output should be 2, 4, 6, 8 ...

  4. Write a program to display only those numbers from a list that satisfy the following conditions

  • The number must be divisible by five

  • If the number is greater than 150, then skip it and move to the next number

  • If the number is greater than 500, then stop the loop given numbers = [12, 75, 150, 180, 145, 525, 50]

  1. Write a program to count the total number of digits in a number using a while loop. given number 4673453

  2. Display numbers from -10 to -1 using while loop

More Questions for Revision

  1. Write a program to print all the numbers from 1 to 100.

  2. Write a program to print all the numbers from 1 to 100 except multiples of 3.

  3. Write a program to print all alphabets from a to z.

  4. given a list of numbers, write a program to print all the numbers that are divisible by 5 and 7.

  5. using a for loop, create a pattern like this:

*
* *
* * *
* * * *
  1. Reverse a number using a while loop. given number 12345, output should be 54321.

  2. Find the sum of even numbers using a while loop

  3. Find the factorial of a number using a while loop. Hint: factorial of a number is the product of all the numbers from 1 to n. example number 5, output should be 120

Last updated