0% found this document useful (0 votes)
8 views2 pages

Python Experiment - 3

python

Uploaded by

Aditya kr. Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Python Experiment - 3

python

Uploaded by

Aditya kr. Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT-3

LOOPS IN PYTHON
PROGRAMS USING FOR LOOP

1. # PROGRAM TO PRINT 1 TO N NUMBERS


for x in range (6):
print(x)

2. # PROGRAM TO PRINT 1 TO N NUMBERS


for x in range (1,6):
print(x)

3. # PROGRAM TO PRINT 1 TO N NUMBERS


for x in range (1,6+1):
print(x)
4. # PROGRAM TO PRINT 1 TO N NUMBERS
n=0
n=int(input(“Enter the value for n:”))
for x in range (1,n+1) :
print(x)

5. # PROGRAM TO FIND THE FACTORIAL OF GIVEN NUMBER


n=int(input(“Enter a number :”))
f=1
for i in range(1, n+1) :
f=f*i
print(“Factorial of “, n , “=” , f)

6. # PROGRAM TO FIND THE REVERSE OF GIVEN NUMBER


n= int (input(“Enter a number :”))
rev =0
for _ in range (4):
d=n%10
rev= rev*10 + d
n = n//10
print (“the reverse of the given number is :”, rev)

7. # PROGRAM TO FIND THE SUM OF DIGITS OF A GIVEN NUMBER


n= int (input (“Enter a number :”))
sum =0
for _ in range(4) :
d=n%10
sum= sum + d
n = n//10
print (“ the sum of digits of a number is :”, sum)
8. #PROGRAM TO PRINT MULTIPLICATION TABLE OF A NUMBER
product=1
n= int (input (“Enter the range :”))
for x in range (1,10+1) :
product= n * x
print( n, “ * “, x, “ = “, product)

You might also like