[Tutor] formatting strings
Steven D'Aprano
steve at pearwood.info
Sat May 9 05:07:02 CEST 2015
On Thu, May 07, 2015 at 06:57:30PM +0000, Tudor, Bogdan - tudby001 wrote:
> Hi,
>
> This is my first time.
> I am using python 3.4.3 on windows 7 64bit.
>
> I am trying to make a binary counter that will prompt for and read a
> decimal number (whole number). Then display all decimal numbers
> starting from 1 up to and including the decimal number entered along
> with the binary representation of the numbers to the screen.
Start by handling a single number:
py> def display_number(n):
... print(n, bin(n))
...
py> display_number(15)
15 0b1111
Now do a loop, displaying each number:
py> for i in range(1, 11):
... display_number(i)
...
1 0b1
2 0b10
3 0b11
4 0b100
5 0b101
6 0b110
7 0b111
8 0b1000
9 0b1001
10 0b1010
Does that help?
--
Steve
More information about the Tutor
mailing list