Sorry guys...this is probably really trivial but i'm new to Python.

How do you remove the first digit from a five digit number called x and then add this new number to the original x.
I need to be able to remove any of the digits and add the new number to the original one.

Thanks for any help

Sorry guys...this is probably really trivial but i'm new to Python.

How do you remove the first digit from a five digit number called x and then add this new number to the original x.
I need to be able to remove any of the digits and add the new number to the original one.

Thanks for any help

I would change the integer to a string then strip the first character off

I'm not sure, without running it myself but I would say:

x=12345
print x+x[0]
#and it should print x+1
#or you could do:
for i in range(len(x)+1):
  i-=1
  print x+x[i]
#and that should produce:
#12346
#12347
#12348
#12349
#12350

once again, I'm not too sure about this

I would change the integer to a string then strip the first character off

I didnt thing you needed to do so with integers, that the index function handled it anyway

x=12345
print x+x[0]

This must be features on the new Python 3.1.1 because it won't work on 2.6.1

Edited 7 Years Ago by gerard4143: n/a

oh, I use 2.6.1 so I guess that I just got it wrong :( but it would be something like this then:

x=12345
tempx=str(x)
print x+int(tempx[0])
#or:
for i in len(x+1):
  i-=1
  print x+int(tempx[i])

Maybe this will work

Editor: How about testing code out before you post it as a solution.

Edited 7 Years Ago by vegaseat: bad code

This article has been dead for over six months. Start a new discussion instead.