How do i validate a user input in python?

christian zelioh

How do i validate a user input in python ? I am writing this code , the user has to put in their name, and it has to be two names separated by a space and the name should contain only letters

def Name():
    n = 0
    name = input('name please\n>>')
    c = name.split(' ')
    while len(c) != 2:
        print('we need two names')
        name = input('name please\n>>')
        c = name.split(' ')

    while True:
        for i in name:
            if i not in r:
                n+=1
        if n > 0:
            print('Letters only')
        else:
            break

Name()
Randy Maldonado

Use .isalpha() and I suggest just doing this recursively.

def Name():
    name = input('name please\n>>')
    c = name.split(' ')
    if len(c) != 2:
        print('we need two names')
        Name()

    for item in c:
        if not item.isalpha():
            print('Letters only')
            Name()

    return name

Name()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i validate integer as user input?

How do I validate user input in a loop?

How do i validate user input that starts with 2 numbers?

How to validate user input in python

How can I validate user-input in python?

How do I validate if the given input is an object in Python?

ReactJS - How do I validate input fields

Jquery how do I validate input field

How do I get user input to use my validate method for a login console application?

How do I validate a user's input and make sure it is the correct type and within a given range?

How do I use a function to validate user input within another function?

How do I validate a user input with int.TryParse to ensure the user entered an integer but also ensure the number was between 1 and 4

How do I get user input from discord chat in python?

How do I get the user to input a number in Python 3?

How do I gather user numerical input into a list in Python?

How do I make a loop for user input in python?

Python- how do I write user input to an Excel file?

How do I check user input against multiple lists python?

How do I get Python to print from 1 to user input?

why can't I validate user input in this way? Python

How do I validate the password of a user created with the User Manager?

How can I validate a Perl regex in user input?

How to validate user input in shiny

How to validate user input in Java?

How to validate input from user within a function? #python3

Python how to validate user input with multiple acceptable options

How do I validate an entry widget in python?

How do I validate input in Django REST framework before creation?

How do I validate two input fields on HTML form?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive