Reputation: 19
How to make input verification in a separate function? the program should take the input sequence 1 and 0
def check(SEQ):
for i in SEQ:
isinstance(i, int)
if not (set(SEQ) == {0, 1} or set(SEQ) == {1} or set(SEQ) == {0}):
return False
else:
return True
def main():
SEQ = [i for i in input("Enter the sequence 0 and 1 ").split()]
while not check(SEQ):
print("Invalid values ")
SEQ = [i for i in input("Enter the sequence 0 and 1 ").split()]
if __name__ == '__main__':
main()
Upvotes: 0
Views: 88
Reputation: 314
Like this:
def check(value):
return all(map(lambda x: x=='1' or x=='0', value.split()))
Upvotes: 1