Int()'s Second Parameter | Interesting


#1


print int("1",2)
print int("10",2)
print int("111",2)
print int("0b100",2)
print int(bin(5),2)
# Print out the decimal equivalent of the binary 11001001.
print int('11001001', 10)
output:
11001001
error:
Oops, try again. It looks like you didn't print out the base 10 equivalent of 11001001.


#2

Careful of what the lesson states:

When given a string containing a number and the base that number is in, the function will return the value of that number converted to base ten.

Binary is represented in base 2, so the lesson is saying that if you use the int function with a binary number and the base that number is in, you will get the base 10 equivalent as a return value.

Hope this helps!


#3

print int('11001001', 2)

I got it right.

Base 10 is numbers:0,1,2,3,4,5,6,7,8,9
Right?


#4

Correct! Base 10 is basically the decimal system in which we use those 10 digits to represent numbers, whereas binary has two numbers (0, 1), hence base 2.


#5

Thank you for your time!


#6

or you can simply print int("201").


#7

Yes, technically you can, but only because the SCT wouldn't catch you out. The point of the lesson is to learn how to convert between number bases.


#8

sorry i dont get it what is the value of that number converted to base ten means exactly iam a little confused about this exercise could you explain it to me


#9

why it types none ???


print int ("11001001" , 2)

and then I get none :slight_smile: seriously!!! .. it told me that I passed the exercise and I can move to the next one but I want to know if possible why that none appeared


#10