Week 5 Unit 6: Self-test
22. October 2024
Question 1
In Python, integer numbers are objects. Therefore, there are methods defined
on integer objects. The method .bit_length()
returns the number of bits
required to represent an integer. Using the function bin()
you can get the
binary representation of an integer. For example, bin(28)
returns 0b11100
.
The digits behind the letter b are the digital representation for the integer 28. There are 5 digits required for this representation, so the method
.bit_length
would return the value 5. What is the output of the following
program?
1000000
❌6
❌7
✅8
❌Question 2
What is the output of the following program?