learning python 2.6 and i can't seem to figure out how to make this code simpler.
def check_csc(code):
cod=list(code)
if len(cod)==3:
if (cod[0]=='0' or cod[0]=='1' or cod[0]=='2' or cod[0]=='3' or cod[0]=='4' or cod[0]=='5' or cod[0]=='6' or cod[0]=='7' or cod[0]=='8' or cod[0]=='9') and (cod[1]=='0' or cod[1]=='1' or cod[1]=='2' or cod[1]=='3' or cod[1]=='4' or cod[1]=='5' or cod[1]=='6' or cod[1]=='7' or cod[1]=='8' or cod[1]=='9') and (cod[2]=='0' or cod[2]=='1' or cod[2]=='2' or cod[2]=='3' or cod[2]=='4' or cod[2]=='5' or cod[2]=='6' or cod[2]=='7' or cod[2]=='8' or cod[2]=='9'):
return True
else:
return False
else:
return False
basically the argument must be less than 999, all integers (obviously) and must be 3 integers.
CodePudding user response:
what is example of parameter?
def check_csc(code):
if int(code) <= 999:
return True
return False
print(check_csc('999')) # True
CodePudding user response:
def check_csc(code):
if str(code).isdigit() and 100 <= code <= 999:
return True
else:
return False
