![]() |
| ||
| Ask user for binary number Hi I am trying to ask the user to input a binary number and checking to see if the input contains 0's and 1's. If not, I want to inform the user that the input was invalid and ask them to retry. Any help to fix my code would be greatly appreciated. binary = int(raw_input("Enter a binary number:")) |
| ||
| Re: Ask user for binary number binary = int(raw_input("Enter a binary number:")) |
| ||
| Re: Ask user for binary number You could use list comprehension as well binary = raw_input() |
| ||
| Re: Ask user for binary number still_testing = True |
| ||
| Re: Ask user for binary number Not to be too terribly picky, but the code in the above post where it uses if int(num) not in [0,1]:will fail if the user enters non-digit characters. If the test were performed with strings it would not fail: if num not in ['0','1']: |
| All times are GMT -4. The time now is 4:53 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC