def controllInput(func:callable, prompt = '>'):
  while True:
    try:
      inputValue = input(prompt)
      value = func(inputValue)
      if type(value) == bool:
        if value:
          return inputValue;
        else:
          print('!!INVALID INPUT!!')
      else:
        return value, inputValue
    except:
      print('!!INVALID INPUT!!')
      
a = controllInput(str.isdigit, 'digit: ')
print(a, type(a))
b = controllInput(int, 'int: ')[0]
print(b, type(b))
c = controllInput(str.isalpha, 'alpha: ')
print(c, type(c))
d = controllInput(lambda x: x.isalpha() and len(x)==5, '5 alpha:')
print(d, type(d))

مشخصات

آخرین مطالب این وبلاگ

آخرین ارسال ها

آخرین جستجو ها