How to check if the user's input is valid Python

check if user already logged in php
check if user is logged in javascript
how to check if user already exists in database in spring mvc
php check login session
check if user login or not
check if user is logged in wordpress
hibernate check if record already exists
how to check user already login or not in php

This is my exercise: get the user's first name, last name and birth year. Create initials from the name (first letter) and calculate the age of the user.

I wrote a script:

def age_name():
    # var= firstName ,lastName ,year
    is_running=True
    firstName =input("What is your name?").lower()
    while is_running==True:
        if firstName.isalpha() and len(firstName)>0:
            lastName = input("What is your last name?").lower()
            if lastName.isalpha() and len(lastName) > 0:
                year = input("What is your birth year?")
                if year.isnumeric() or len(year)==4:
                    year=int(year)
                    print("Your initials are {0}{1} and your age is {2}.".format(firstName[0],lastName[0],2018-year))
                    #print("Your initials are ",firstName[0],lastName[0],"and your age is ",str(2018-year))
                else:
                    print("invalid year. please type your birth year")
                    year = input("What is your birth year?")
            else:
                print("invalid last name. please type your last name")
                lastName = input("What is you last name?").lower()
        else:
            print("invalid name. please type your name")
            firstName = input("What is you name?").lower()

age_name()

I've tested the code and this is what I get:

What is your name?p5
invalid name. please type your name
What is you name?peter
What is your last name?p5
invalid last name. please type your last name
What is you last name?pen
What is your last name?pen
What is your birth year?p5
invalid year. please type your birth year
What is your birth year?10
What is your last name?pen
What is your birth year?1800
Your initials are pp and your age is 218.
What is your last name?

First of all, I think my code is a bit repetitive - if someone has ideas to shorten it. Second and biggest problem - I keep getting the last name question. Where is my bug?

How does this look?

def age_name():
    firstname=input("What is your name?")
    while firstname.isalpha()!=True:
        print("Invalid name, enter again")
        firstname = input("What is your name?")
    lastname = input("What is your last name?")
    while lastname.isalpha()!=True:
        print("Invalid name, enter again")
        lastname = input("What is your last name?")
    year = input("What is your birth year?")
    while len(year) != 4 and year.isdigit():
        print("Invalid year, enter again")
        year = input("What is your birth year?")
    year = int(year)
    print("First Name:",firstname,"\nLast Name:",lastname,"\nBirth Year:",year)

age_name()

How to check if user exist in database using Hibernate Validator, During work on my current project, Library Portal, I have encounter a problem with checking if a user is already in the database during registering new one, i.e. if  I want to be able to check if the user running the current thread is: a Domain User a Local User of the machine There are some cavaets: i do not know (or care) if the machine is domain joined be

I think the best readable while least error prone way would be sth like below. The input lines are programmed only once each and everything is dependent on the state of response_invalid.

def age_name():
    response_invalid = True
    while response_invalid:
        firstName = input("What is your name?").lower()
        if firstName.isalpha() and len(firstName)>0:
            response_invalid = False
        else:
            print("invalid name. please type your name")
    response_invalid = True
    while response_invalid:
        lastName = input("What is your last name?").lower()
        if lastName.isalpha() and len(lastName) > 0:
            response_invalid = False
        else:
            print("invalid last name. please type your last name")
    response_invalid = True
    while response_invalid:
        year = input("What is your birth year?")
        if year.isnumeric() or len(year)==4:
            response_invalid = False
        else:
            print("invalid year. please type your birth year")
    year=int(year)
    print("Your initials are {0}{1} and your age is {2}.".format(firstName[0],lastName[0],2018-year))

However, this is the verbose variant of a very common way to implement this, which is I think the shortest, but a little rude...:

def age_name():
    while True:
        firstName = input("What is your name?").lower()
        if firstName.isalpha() and len(firstName)>0:
            break
        print("invalid name. please type your name")
    while True:
        lastName = input("What is your last name?").lower()
        if lastName.isalpha() and len(lastName) > 0:
            break
        print("invalid last name. please type your last name")
    while True:
        year = input("What is your birth year?")
        if year.isnumeric() or len(year)==4:
            break
        print("invalid year. please type your birth year")
    year=int(year)
    print("Your initials are {0}{1} and your age is {2}.".format(firstName[0],lastName[0],2018-year))

How to check if a user is in a specific role?, If you only need this for current user current_user_can() accepts both roles and capabilities. UPDATE: Passing a role name to current_user_can() is no longer  If you're going to create a user with specific name, then you have to check that the user name is available (by running the marc_s's check). In addition, due to 1-to-1 link between login and user you must check that no user is associated with the login (by running the gbn's check). – Alex Klaus May 10 '17 at 4:10

That looks so much better. Thank you. but look at the error I get when I type year whis letters: What is your birth year?g5 ValueError: invalid literal for int() with base 10: 'g5'. i've changed the last while operator from and to or and it works beautifully.

How to check if a user exists? - General Support, Can someone tell me why this is returning true for $users->get("username") when the user definitely doesn't exist? I have tried various combos,  Check permission level for all of accounts on the computer. Click Start . Open the Control Panel . Open User Accounts . The user accounts on the computer will be listed on the screen. Each name should display the permission level.

How to Check if User Accounts are Administrator or Standard Users , Standard users can't run anything that requires elevated privileges. In this tutorial, we show you a few ways to check if a user is a Standard or Administrator  Hit Windows+R, type “lusrmgr.msc” into the Run box, and then hit Enter. In the “Local Users and Groups” window, select the “Users” folder, and then double-click the user account you want to look at. In the properties window for the user account, switch to the “Member Of” tab.

How to Check If User Logged In - Questions, But how do I check whether a user is already logged in or not so that I can automatically redirect them back to urlA from the sign-in widget so  Powershell scipt to check if User is Member of a Group The following powershell script checks whether the given user is member of the given group. We are using the parameter -Recursive with Get-ADGroupMember cmdlet to get nested group members along with direct group members.

How can I check if a user is logged in?, Please I need to check or verify if a user is logged in Programmatically.Basically I am creating another page on nopCommerce, where by some control So "test" is found as a SAM account name, but is not an actual AD user object (another type of object, see below). Since the SAM account name is unique per AD, I suppose the distinction is not always needed between a user or other type of object, but if it is, here's how to verify it really is a user :

Comments
  • Looks like you never alter is_running?
  • Welcome to StackOverflow. I would consider putting each of the three parts (first name, last name, year) in a separate function. Currently, an invalid entry messes up the flow. You should set isRunning = False at some point, once it is finished.
  • To create specific functions and error handling is also the consensus of this canonical thread