Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Loops in python Learn in easy steps
SUBMITTED BY:
Guest
DATE:
Dec. 15, 2013, 8:32 a.m.
FORMAT:
Python
SIZE:
1.2 kB
Raw
Download
Tweet
HITS:
781
Go to comments
Report
# loop
# display n to 1
n
=
5
# 'C'
# while(n)
# {
# printf("%d\n", n);
# --n;
# }
# Python
# leader:
# suite
n
=
5
while
n
:
print
(
n
)
n
-=
1
# infinte loop
#n = 5
#while n :
# print(n)
#n -= 1
# ok
n
=
5
while
n
:
print
(
n
)
n
-=
1
# indentation by tab
n
=
5
while
n
:
print
(
n
)
n
-=
1
# comibination of tab and spaces : not reco; error in 3.x
#n = 5
#while n :
# print(n)
# n -= 1
# reco: 4 spaces for indentation
a
=
[
[
"dhoni"
,
80
,
40
,
50
],
[
"kohli"
,
20
,
100
,
30
],
[
"raina"
,
78
,
52
,
33
],
[
"sehwag"
,
200
,
0
,
9
]
]
# len : polymorphic
print
(
"
\n
"
,
"size : "
,
len
(
a
))
i
=
0
while
i
<
len
(
a
)
:
print
(
a
[
i
][
0
])
j
=
1
total
=
0
while
j
<
len
(
a
[
i
])
:
total
+=
a
[
i
][
j
]
j
+=
1
i
+=
1
print
(
total
)
#increase indention for suite wrt leader
# can increase indentation following the leader
# when decreasing indentation, it should match the
# indentation of some earlier stmt
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus