Post Reply 
Test for Numeric in Prime Python
11-24-2021, 04:30 AM (This post was last modified: 11-24-2021 04:30 AM by toml_12953.)
Post: #1
Test for Numeric in Prime Python
Since MicroPython doesn't have the isnumeric() attribute, here's a little function that can determine if a string consists of only digits or not:

Code:
# this function returns True if the argument is numeric, False if not
def isnumeric(number):
    for i in number:
        if i<'0' or i>'9':
            return False
    return True

This can be used after an input to make sure only digits have been entered. Decimal points and exponents are not allowed.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)