Basics of Python-10

Day -10

For Loop :

For loop is used to iterate a sequence of data items.

let's solve some examples:

  1. Write a python program to find the factorial of a number :
n=int(input("Enter the number - "))
m=1
for i in range(1,n+1):
    m=m*i 
print("The factorial of number is -",m)

output :


  1. Write a python program to print the sum of the digit of a number in the range.
n=int(input("enter the number "))
m=int(input("Enter second number"))
sum=0
for i in range(n,m+1):
    sum=sum+i 
print(sum)

output:


  1. Write a program to print the multiplication table of 7
n=int(input("Enter the number :"))
for i in range(1,11):
    print(n,"*",i,"=",n*i)

output :


More problems on for loop :

Write a program to convert temperature in Fahrenheit to centigrade.

Write a program to reverse a number

Write a program to print the following patterns -

In my next blog, You will get to know! How to write a program to solve patterns by using for loop.

Thank you !!

0
Subscribe to my newsletter

Read articles from Priya Chakraborty directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Priya Chakraborty
Priya Chakraborty

Hello, I'm Priya Chakraborty, a dedicated B.Tech student in Electrical Engineering at Siliguri Institute Of Technology. I'm an enthusiastic learner, constantly seeking to expand my skill set and knowledge base. With a solid foundation in programming languages such as C, R, Python, and MySQL, I'm poised to tackle complex technical challenges. But my passions extend beyond the realm of engineering. I'm also an aspiring content writer, driven by a curiosity to communicate ideas, both technical and non-technical, in a way that captivates and educates. My journey is defined by a relentless pursuit of self-improvement, coupled with strong communication skills. I believe in the power of continuous learning and the importance of sharing knowledge.