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))

مشخصات

تبلیغات

محل تبلیغات شما

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

محل تبلیغات شما محل تبلیغات شما

آخرین وبلاگ ها

برترین جستجو ها

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

پس از فصل سرد سایت مداحی John ماشین های سنگین فارس دانلود Branden آزمایشی free pc game