#printing natural nos and sum from 1 to 100 – while loop
#printing squares of odd nos fro 1 to 100
x=1
while x<=100:
print(x* x, end="t")
x+=2
print(" bye")
56 63 70 77 84 91 98
sum of the nos divisible by 7 from 1 to 100 is : 539
n!=n*(n-1)*(n-2)*(n-3)……..1
5!=5*4*3*2*1
4!=4*3*2*1
6!=6*5*4*3*2*1
1!=1
Factorial of an integer
enter a no 5
Factorial is 120
Factorial of an integer
Factorial explanation( 5! )
n=5
f=1 ,
n>0 True as 5>0
f=f*n=1*5=5
n=n-1=5-1=4
4>0 true
f=5*4=20
n=4-1=3
3>0 ,true
f=20*3=60
n=3-1=2
2>0 ,true
f=60*2=120
n=2-1=1
1>0 ,true
f=120*1=120
n=1-1=0
0>0 ,False
FIRST
2ND
3RD
4TH
5TH
120
Factorial of an integer
Output
enter a no 5
Factorial of 5 is 120
>>> ================================ RESTART
================================
>>>
enter a no 4
Factorial of 4 is 24
>>> ================================ RESTART
================================
>>>
enter a no 7
Factorial of 7 is 5040
Factorial explanation( 4! )
n=4
f=1
for i in range(n,0,-1)
f=f* i=1*4=4
i=i-1= 4-1= 3
f=4*3=12
i=3-1=2
f=12*2=24
i=2-1=1
f=24*1=24
i=1-1=0
FIRST
2ND
3RD
4TH
24
# To find the sum of digits in a no
Give an integer no 345
sum of the of digits = 12
>>> ================================ RESTART
================================
>>>
Give an integer no 1234
sum of the of digits = 10
SUM OF DIGIT OF 345
Give an integer no x= 345
s=r=0
345>0 true
r=345%10=5
s=s + r=0+5=5
x=345//10=34
3>0 true
3%10=3
s=s + r=9+3=12
x=3//10=0
x=0>0 False
FIRST 3rd
34>0 true
r=34%10=4
s=s+r=5+4=9
x=34//10=3
2nd 12
REVERSE OF A NO
REVERSE OF DIGIT OF 345
Give an integer no x=345
s=r=0
345>0 true
r=345%10=5
s=s*10 + r=0+5=5
x=345//10=34
3>0 true
3%10=3
s=s*10 + r=54*10+3=543
x=3//10=0
x=0>0 False
FIRST
3rd
34>0 true
r=34%10=4
s=s*10+r=5*10+4=54
x=34//10=3
2nd 543
Give an integer no 345
Reverse no is 543
>>> ================================ RESTART
================================
>>>
Give an integer no 123
Reverse no is 321
>>> ================================ RESTART
================================
>>>
Give an integer no 121
Reverse no is 121
PALINDROME NUMBER
output
Give an integer no 345 ------x
345 is not a palindrome number
S --- 543 , y----345
>>>
================================
RESTART
================================
>>>
Give an integer no 131
S --- 131 , y----131
131 is a palindrome number
PALINDROME CHECK OF DIGIT OF 345
Give an integer no x=345
s=r=0
345>0 true
r=345%10=5
s=s*10 + r=0+5=5
x=345//10=34
3>0 true
3%10=3
s=s*10 + r=54*10+3=543
x=3//10=0
x=0>0 False
FIRST
3rd
34>0 true
r=34%10=4
s=s*10+r=5*10+4=54
x=34//10=3
2nd 543
345
y s
Jump Statements – break &
continue
break statement in python is used to
terminate the containing loop for any
given condition. Program resumes from
the statement immediately after the
loop
Continue statement in python is used to
skip the statements below continue
statement inside loop and forces the
loop to continue with next value.
Example –
break
for i in range(1,20):
if i % 6 == 0:
break
print(i)
print(“Loop Over”)
The above code produces output
1
2
3
4
5
Loop Over
when the value of i reaches to 6 condition will becomes
True and loop will end and messageV“IN
LOoDo
K
U
p
M
A
O
R
V
vE
R
eM
rA
”,
P
G
wT
(
iC
llS
)
,
bK
V
eO
pE
F
rK
iA
nN
tP
eU
R
d&

1 DEC LOOP REVISION.pptx

  • 1.
    #printing natural nosand sum from 1 to 100 – while loop
  • 2.
    #printing squares ofodd nos fro 1 to 100 x=1 while x<=100: print(x* x, end="t") x+=2 print(" bye")
  • 3.
    56 63 7077 84 91 98 sum of the nos divisible by 7 from 1 to 100 is : 539
  • 4.
  • 5.
    enter a no5 Factorial is 120 Factorial of an integer
  • 6.
    Factorial explanation( 5!) n=5 f=1 , n>0 True as 5>0 f=f*n=1*5=5 n=n-1=5-1=4 4>0 true f=5*4=20 n=4-1=3 3>0 ,true f=20*3=60 n=3-1=2 2>0 ,true f=60*2=120 n=2-1=1 1>0 ,true f=120*1=120 n=1-1=0 0>0 ,False FIRST 2ND 3RD 4TH 5TH 120
  • 7.
  • 8.
    Output enter a no5 Factorial of 5 is 120 >>> ================================ RESTART ================================ >>> enter a no 4 Factorial of 4 is 24 >>> ================================ RESTART ================================ >>> enter a no 7 Factorial of 7 is 5040
  • 9.
    Factorial explanation( 4!) n=4 f=1 for i in range(n,0,-1) f=f* i=1*4=4 i=i-1= 4-1= 3 f=4*3=12 i=3-1=2 f=12*2=24 i=2-1=1 f=24*1=24 i=1-1=0 FIRST 2ND 3RD 4TH 24
  • 10.
    # To findthe sum of digits in a no Give an integer no 345 sum of the of digits = 12 >>> ================================ RESTART ================================ >>> Give an integer no 1234 sum of the of digits = 10
  • 11.
    SUM OF DIGITOF 345 Give an integer no x= 345 s=r=0 345>0 true r=345%10=5 s=s + r=0+5=5 x=345//10=34 3>0 true 3%10=3 s=s + r=9+3=12 x=3//10=0 x=0>0 False FIRST 3rd 34>0 true r=34%10=4 s=s+r=5+4=9 x=34//10=3 2nd 12
  • 12.
  • 13.
    REVERSE OF DIGITOF 345 Give an integer no x=345 s=r=0 345>0 true r=345%10=5 s=s*10 + r=0+5=5 x=345//10=34 3>0 true 3%10=3 s=s*10 + r=54*10+3=543 x=3//10=0 x=0>0 False FIRST 3rd 34>0 true r=34%10=4 s=s*10+r=5*10+4=54 x=34//10=3 2nd 543
  • 14.
    Give an integerno 345 Reverse no is 543 >>> ================================ RESTART ================================ >>> Give an integer no 123 Reverse no is 321 >>> ================================ RESTART ================================ >>> Give an integer no 121 Reverse no is 121
  • 15.
  • 16.
    output Give an integerno 345 ------x 345 is not a palindrome number S --- 543 , y----345 >>> ================================ RESTART ================================ >>> Give an integer no 131 S --- 131 , y----131 131 is a palindrome number
  • 17.
    PALINDROME CHECK OFDIGIT OF 345 Give an integer no x=345 s=r=0 345>0 true r=345%10=5 s=s*10 + r=0+5=5 x=345//10=34 3>0 true 3%10=3 s=s*10 + r=54*10+3=543 x=3//10=0 x=0>0 False FIRST 3rd 34>0 true r=34%10=4 s=s*10+r=5*10+4=54 x=34//10=3 2nd 543 345 y s
  • 18.
    Jump Statements –break & continue break statement in python is used to terminate the containing loop for any given condition. Program resumes from the statement immediately after the loop Continue statement in python is used to skip the statements below continue statement inside loop and forces the loop to continue with next value.
  • 19.
    Example – break for iin range(1,20): if i % 6 == 0: break print(i) print(“Loop Over”) The above code produces output 1 2 3 4 5 Loop Over when the value of i reaches to 6 condition will becomes True and loop will end and messageV“IN LOoDo K U p M A O R V vE R eM rA ”, P G wT ( iC llS ) , bK V eO pE F rK iA nN tP eU R d&