0

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

3
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by leegeorg07
0

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

0

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

0

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

0

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 by gerard4143: n/a

0

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 by vegaseat: bad code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.