* Ghadir Ghasemi <ghasemm...@leedslearning.net> [2013-01-11 21:51]:
> Hi, I made a program called binary/denary convertor. Can anyone tell
> me about how I could stop the user entering a binary number with more
> than 8 numbers or 8 bit by repeating the question over and over until
> they do enter a correct binary number( 8-bit or less) Here is the
> code. I started off by entering 'len' function.
> 
> def add_binary_numbers(num1, num2):
>     return num1 + num2
> 
> num1 = int(input('please enter the first 8 bit binary number: '),2)
> if len(num1) > 8:
>     print("please enter an 8 bit binary number")
> return int(num1,2)
> num2 = int(input('please enter the second 8 bit binary number: '),2)
> result = add_binary_numbers(num1, num2)
> print('the result is', bin(result)[2:])

It looks like the first thing you need to do is figure out how to use a
loop (eg, while loop, for loop).  I would recommend thinking about some
pseudocode to determine your program's flow and then try to build
something to accomplish that.

-- 
David Rock
da...@graniteweb.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to