python - How to make a program distinguish between 1-13 INSIDE a raw_input -
hello code:
def function(): n1=1 n2=2 n3=3 n4=4 n5=5 n6=6 n7=7 n8=8 n9=9 n10=10 n11=11 n12=12 n13=13 n = raw_input("number (with optional text): ") if n1 or n2 or n3 or n4 or n5 or n6 or n7 or n8 or n9 in n: print "not want" elif n12 or n13 in n: print "dis want" function()
i'm trying create raw_input status take set 13 (as detects input has either 1 or 3 in message) can't (please, know can create range in list , accepts set each number separately, it's part of code programme i'm working on in user can set whether words want, long numbers input, doesn't distinguish between 1 or 11 example). hope can help :)
if '12' in n or '13' in n: print 'ok' else: print 'wrong'
if have more elements in allowed set, improve utilize any()
comprehension:
if any(str(x) in n x in range(1, 14)): print 'found number range 1-13 in string'
python
No comments:
Post a Comment