List of loop programming exercises
1.Write a python program to print all natural numbers from 1 to n.
2.Write a python program to print all natural numbers in reverse (from n to 1).
3.Write a python program to print all alphabets from a to z.
4.Write a python program to print all even numbers between 1 to 100.
5.Write a Python program to print all odd number between 1 to 100.
6.Write a Python program to find sum of all natural numbers between 1 to n.
7.Write a Python program to find sum of all even numbers between 1 to n.
8.Write a Python program to find sum of all odd numbers between 1 to n.
9.Write a Python program to print multiplication table of any number.
10.Write a Python program to Count number of digits in a number.
11.Write a Python program to find first and last digit of a number.
12.Write a Python program to find sum of first and last digit of a number.
13.Write a Python program to swap first and last digits of a number.
14.Write a Python program to calculate sum of digits of a number.
15.Write a Python program to calculate product of digits of a number.
16.Write a Python program to enter a number and print its reverse.
17.Write a python program to check whether a number is palindrome or not.
18.Write a Python program to find frequency of each digit in a given integer.
19.Write a Python program to enter a number and print it in words.
20.Write a Python program to print all ASPCII character with their values.
21.Write a Python program to find power of a number using for loop.
22.Write a Python program to find all factors of a number.
23.Write a Python program to calculate factorial of a number.
24.Write a Python program to find HCF (GCD) of two numbers.
25.Write a Python program to find LCM of two numbers.
26.Write a Python program to Check whether a number is Prime number or not.
27.Write a Python program to print all Prime numbers between 1 to n.
28.Write a Python program to find sum of all prime numbers between 1 to n.
29.Write a Python program to find all prime factors of a number.
30.Write a Python program to check whether a number is Armstrong number or not.
31.Write a Python program to print all Armstrong numbers between 1 to n.
32.Write a Python program to cheCk whether a number is Perfect number or not.
33.Write a Python program to print all Perfect numbers between 1 to n.
34.Write a Python program to check whether a number is Strong number or not.
35.Write a Python program to print all Strong numbers between 1 to n.
36.Write a Python program to print FibonacCi series up to n terms.
37.Write a Python program to find one's complement of a binary number.
38.Write a Python program to find two's complement of a binary number.
39.Write a Python program to convert Binary to Octal number system.
40.Write a Python program to convert Binary to Decimal number system.
41.Write a Python program to convert Binary to Hexadecimal number system.
42.Write a Python program to Convert OCtal to Binary number system.
43.Write a Python program to convert Octal to DeCimal number system.
44.Write a Python program to convert Octal to Hexadecimal number system.
45.Write a Python program to convert Decimal to Binary number system.
46.Write a Python program to convert Decimal to Octal number system.
47.Write a Python program to convert Decimal to Hexadecimal number system.
48.Write a Python program to convert Hexadecimal to Binary number system.
49.Write a Python program to convert Hexadecimal to Octal number system.
50.Write a Python program to convert Hexadecimal to Decimal number system.
51.Write a Python program to print Pascal triangle upto n rows.
52.Star pattern programs - Write a Python program to print the given star patterns.
53.Number pattern programs - Write a Python program to print the given number
patterns.
54.Print all elements of a list using for loop.
55.You are given with a list of integer elements. Make a new list which will store
square of elements
of previous list.
56.Write a Python program to find those numbers which are divisible by 7 and
multiple of 5, between 1500 and 2700 (both included).
57.Write a Python program to convert temperatures to and from celsius, fahrenheit.
[ Formula : c/5 = f-32/9 [ where c = temperature in celsius and f = temperature in
fahrenheit ]
Expected Output :
60�C is 140 in Fahrenheit
45�F is 7 in Celsius
58. Write a Python program to construct the following pattern, using a nested for
loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
59.Write a Python program that accepts a word from the user and reverse it.
60.Write a Python program to count the number of even and odd numbers from a series
of numbers.
61.Write a Python program that prints each item and its corresponding type from the
following list.
Sample List : datalist = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12],
{"class":'V', "section":'A'}]
62. Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
63.Write a Python program which iterates the integers from 1 to 50. For multiples
of three print "Fizz" instead of the number and for the multiples of five print
"Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
Sample Output :
fizzbuzz
1
2
fizz
4
buzz
64. Write a Python program that accepts a string and calculate the number of digits
and letters.
65.Write a Python program to find numbers between 100 and 400 (both included) where
each digit of a number is an even number. The numbers obtained should be printed
in a comma-separated sequence.
66. Write a Python program to print alphabet pattern 'A'.
***
* *
* *
*****
* *
* *
* *
67.Write a Python program to print alphabet pattern 'D
****
* *
* *
* *
* *
* *
****
68.Write a Python program to construct the following pattern
1
22
333
4444
55555
666666
7777777
88888888
999999999
69. Write a program in python to calculate the sum of the series (1*1) + (2*2) +
(3*3) + (4*4) + (5*5) + ... + (n*n).
Input the value for nth term: 5
1*1 = 1
2*2 = 4
3*3 = 9
4*4 = 16
5*5 = 25
The sum of the above series is: 55
70.Write a program in python to calculate the series (1) + (1+2) + (1+2+3) +
(1+2+3+4) + ... + (1+2+3+4+...+n).
Input the value for nth term: 5
1 = 1
1+2 = 3
1+2+3 = 6
1+2+3+4 = 10
1+2+3+4+5 = 15
The sum of the above series is: 35
71. Write a program in python to print a square pattern with # character.
# # # #
# # # #
# # # #
# # # #
72. Write a program in python to display the sum of the series [ 9 + 99 + 999 +
9999 ...].
Sample Output:
Input number of terms: 5
9 99 999 9999 99999
The sum of the sarise = 111105
73. Write a program in python to find the number and sum of all integer between 100
and 200 which are divisible by 9.
74. Write a program in python to Check Whether a Number can be Express as Sum of
Two Prime Numbers.
Input a positive integer: 20
20 = 3 + 17
75.Write a program in python to make such a pattern like a pyramid with numbers
increased by 1.
Input number of rows: 4
1
2 3
4 5 6
7 8 9 10
76.Write a program in python to print the Floyd's Triangle.
1
01
101
0101
10101
77.Write a program in python to display the pattern like a diamond.
*
***
*****
*******
*********
*******
*****
***
*
78.Write a program in python to display Pascal's triangle like pyramid.
1
1 1
1 2 1
1 3 1 3
1 4 6 4 1
79. Write a program in python to display Pascal's triangle like right angle
traingle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
80.Write a program in python to display such a pattern for n number of rows using
number. Each row will contain odd numbers of number. The first and last number of
each row will be 1 and middle column will be the row number.
1
121
12321
1234321
123454321
81.Write a program in python to print a pattern like highest numbers of columns
appear in first row.
12345
2345
345
45
5
82.Write a program in python to find the frequency of each digit in a given
integer.