Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Python :Sum of digits eg #2
SUBMITTED BY:
Guest
DATE:
Dec. 16, 2013, 8:42 a.m.
FORMAT:
Python
SIZE:
387 Bytes
Raw
Download
Tweet
HITS:
804
Go to comments
Report
# find sum of digits
n
=
input
(
"enter an integer : "
)
# slicing : similar to range
# always [] while indexing or slicing on any data structure
#print (n[2]) # indexing
#print (n[2:4]) # slicing
#print (n[2:])
#print (n[:4])
#print (n[2:6:2])
print
(
type
(
n
))
i
=
0
total
=
0
while
i
<
len
(
n
)
:
total
+=
int
(
n
[
i
])
i
+=
1
print
(
total
)
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus