-2

How do I count and PRINT digits that start with triple figures such as 001,002,003,004 etc.. some simple codes will be appreciated!.Thank you

repzero
  • 8,254
  • 2
  • 18
  • 40
  • 6
    Please define how numbers come to be part of the same group. Also, what have you tried, and how is it different from the expected output? – inspectorG4dget Nov 08 '14 at 22:18
  • Note that in Python 2.x e.g. `020 == 16` – jonrsharpe Nov 08 '14 at 22:28
  • show your expected output – Hackaholic Nov 08 '14 at 22:39
  • I just don't understand why members on this site would vote certain question down because it is unclear..if the question is unclear, PLEASE REQUEST MORE INFORMATION TO HELP THE PERSON ASKING THE QUESTION.if you don't know the answer just leave the question unanswered and don't vote it down IF IT DOESN'T VIOLATE STACK OVERFLOW RULES...I hate pricks like these.. – repzero Nov 08 '14 at 23:22
  • @Xorg: I wrote an answer concerning the formatting but what do you mean with "count". Where is this data that you have to count? – Matthias Nov 10 '14 at 10:46
  • @Matthias Great work!..this is what i was looking for.. – repzero Nov 11 '14 at 00:22
  • @Matthias: What i was looking for was counting numbers not like "1,2,3" but "01,02,03,etc"..your answer solved my question..i am trying to map string indices to these numbers. For example "001" mean "string[0]+string[0]+string[1]" – repzero Nov 11 '14 at 00:37
  • @Matthias: I would be grateful if you can provide some input the another question at http://stackoverflow.com/questions/26831690/is-it-possible-to-pickle-itertools-product-in-python – repzero Nov 11 '14 at 00:43
  • @Xorg: Sorry, no question for me. :-( – Matthias Nov 11 '14 at 07:37

2 Answers2

1

Have a look at the strings format method and the Format String Syntax.

for i in range(1, 4):
    print('{0:0>3}'.format(i))

Result:

001
002
003
004
Matthias
  • 12,873
  • 6
  • 42
  • 48
0

assuming your digits are initially in string format:

x = "001, 002, 003, 004, 005"
y = x.split(", ")
total = 0 # total sum of all the numbers
count = 0 # number of values
for i in y:
    total += int(i)
    count += 1

print("Total = %d\nCount = %d" % (total, count))
Shahzad
  • 2,033
  • 1
  • 16
  • 23