[Photo attached] Python, I'd like to ask you a syntax question for checking integer strings.

Asked 2 years ago, Updated 2 years ago, 18 views

You want to create a Python function that corresponds to this condition. How do I determine if the data that came in as a string value is an integer string?

def is_validate_number(user_input): if user_input >= 3 and user_input < 20: return True else: return False

What syntax should I put before the if statement in this function?

python

2022-09-22 14:57

1 Answers

def is_validate_number(user_input): 
    if user_input.isnumeric() and user_input >= 3 and user_input < 20: 
        return True 
    else:     
        return False

Use the str.isnumeric function. True if it is a number.


2022-09-22 14:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.