How do you convert to base 10 in python?
Errors I get are Show
asked Feb 9, 2011 at 15:09
1
Isn't
answered Feb 9, 2011 at 15:15
eumiroeumiro 198k33 gold badges294 silver badges259 bronze badges 2 You're confusing Python with... Perl or something...
answered Feb 9, 2011 at 15:12
2 A more comprehensive solution to this problem may look like this:
Basically whilst converting a number to base 10 it's easiest to start from the last digit, multiply it by the base raised to the current position (DIGITS.index(n) * base ** i). BTW, in my understanding it's a Python exercise, but if it's not there's a builtin function for that - int:
answered Feb 9, 2011 at 16:59
Other bugs in the code:
answered Feb 9, 2011 at 15:21
kefeizhoukefeizhou 6,06410 gold badges40 silver badges55 bronze badges There are many errors in your code. To begin with,
is not Python syntax at all. What you probably want is
Furthermore, the
part should probably be
but actually, there is no need to special-case this at all. Another problem is that you interpreting the first character as "ones", i.e. lowest significant. There are a few more problems, but maybe this will get you going... That said, you could simply use
answered Feb 9, 2011 at 15:17
Sven MarnachSven Marnach 544k114 gold badges914 silver badges816 bronze badges 2
answered Feb 9, 2011 at 21:18
Hugh BothwellHugh Bothwell 53.7k7 gold badges81 silver badges98 bronze badges You probably want
or
answered Feb 9, 2011 at 15:13
Tim PietzckerTim Pietzcker 318k56 gold badges494 silver badges550 bronze badges How do you do base 10 in python?Description. The log10() method returns base-10 logarithm of x for x > 0.. Syntax. Following is the syntax for log10() method − import math math.log10( x ) ... . Parameters. x − This is a numeric expression.. Return Value. This method returns the base-10 logarithm of x for x > 0.. Example. ... . Output.. How do you convert binary to base 10 in python?In Python, you can simply use the bin() function to convert from a decimal value to its corresponding binary value. And similarly, the int() function to convert a binary to its decimal value. The int() function takes as second argument the base of the number to be converted, which is 2 in case of binary numbers.
How do you convert base 8 to base 10?If you have a sequence of base 8 digits you want to convert to a base 10 number, process them from left to right, keeping a total you initialize at zero. For each digit x, set the total to 8*total+x. After processing the last digit, the total will be the base ten value of the base 8 sequence.
|