입력을 확인하고 다시 시도 값의 오류

코드 예제

0
0

입력을 확인하고 다시 시도 값의 오류

#You can test this with check_input_type(int, lambda: input("Your text here:"))

age = check_input_type(int, lambda: input("Enter your age"))

def check_input_type(type_, func):
    try: 
        res = func()
        res = type_(res)
        is_not_correct_type = True
    except ValueError:
        is_not_correct_type = False
    
    while not is_not_correct_type:
        print(f"your input: '{res}' was of type '{type(res)}' cannot be converted to a {type_}. Please try again.")
        try:
            res = func()
            res = type_(res)
            is_not_correct_type = True
        except ValueError:
            pass
    return res

비슷한 페이지

예제가있는 유사한 페이지

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................