Python Program to Print all the Numbers in a Range Divisible by Given Number

 Hey There,


In this blog, I have shown how to print all the numbers in a range that are divisible by given number.


Taking n value from the user :  n = int(input("Enter a number"))


To run in a range we need to take a for loop that can be done as : for i in range(1,26)
Here I want to print all the numbers in a range that starts form 1 and ends at 25,26 is exclusive.


To check number is divisible by given number(n), we do that by checking it's remainder.If remainder is 0,then that number is divisible by n.That can be written as:
if  i%n==0:


If the above if condition satisfies then we can print i value as : print(i)


Now,solution is as follows :

       n = int(input("Enter a number"))
              for i in range(1,26):
                           if i % n ==0:
                                   print(i)

Output :

Python Program to Print all the Numbers in a Range Divisible by Given Number

Video Tutorial:




Comments

Popular posts from this blog

Python Program to Swap First and Last Element of a Given List

Python Program to Calculate the Average of Numbers in a Given List

Python Program to Put Even and Odd Elements of a List into Two Different Lists