J
J
Jalal Nasirov2021-06-28 08:36:02
Python
Jalal Nasirov, 2021-06-28 08:36:02

How to check if there are letters and NUMBERS ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁰ in a variable?

a = str(input('> > > '))
if True:
    for x in a:
        
        if x.isdigit() == True:
            #хабр не распознает некоторые из эти цифр
            if x == '¹' or x == '²' or x == '³' or x == '⁴' or x == '⁵' or x == '⁶' or x == '⁷' or x == '⁸' or x == '⁹' or x == '⁰':
                
                print(False)

            else:
                
                age = int(age)
                if age <= 18 or age >= 100:
                    print(False)
                else:
                    age = str(age)
                    print(True)
                    # КОД ...
        else:
            
            print(False)


The age variable must contain only numbers. This is done by isdigit() , but it also accepts this: ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁰ digits, so it outputs True if there are any in the variable. With the help of the code, I can check each character and sort it through if else . But I need the code to check each character, and only after that, depending on whether it contains letters or ¹²³⁴⁵⁶⁷⁸⁹⁰ , executes a certain code. You cannot use global variables. And apparently you need to do it all in one function.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
12rbah, 2021-06-28
@Best_Loops

link there are many examples

try:
    val = int(userInput)
except ValueError:
    print("That's not an int!")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question