Vstupná kontrola a opakovanie hodnota chyba

Príklady kódu

0
0

vstupná kontrola a opakovanie hodnota chyba

#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

Podobné stránky

Podobné stránky s príkladmi

V iných jazykoch

Táto stránka je v iných jazykoch

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