0

My task is doing a base converter. I thought of switching it to base 10 and then switch it to the wanted base. So I want to get a string and them put it in a list, and slice it and after that to use the sliced parts:

s=input()
NumList=[s]
NumList[::]

Is there any way of doing it? Do you have any better idea?

4
  • 4
    I've re-read the question a couple of times, and can't make heads nor tails of it.
    – NPE
    Dec 4, 2012 at 16:55
  • 1
    Your question is very unclear. I can understand that you want to convert numbers from one base to another base. But I cannot understand anything past that point. What does converting numbers between bases have to do with slicing strings?
    – HerrKaputt
    Dec 4, 2012 at 16:57
  • I'm sorry, I'll try to clear it: Dec 4, 2012 at 17:00
  • my input should be at this form: 1111 2 5 (means the number 1111 in base 2 needs to be switched to base 5) Dec 4, 2012 at 17:01

2 Answers 2

1

You split up your input string like this:

(number, from_base, to_base) = s.split()

2
  • thank you! i tried now to do power: from_base^i(some variable) Dec 4, 2012 at 17:32
  • while(i,pow(from_base,i),i+1) : sum+=i Dec 4, 2012 at 17:32
0

You can split the string received from input by space and thereafter process it according to your needs.

s = input()
ls = s.split() // ls is a list.
1
  • just s.split() space (' ') is default
    – akaRem
    Dec 4, 2012 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.