lundi 16 août 2021

I need python to to check if variable is an integer using the input() command

I need python to check if a variable is an integer or not, then act accordingly.

Here is the pertinent code:

def data_grab():
    global fl_count #forklift count
    print("How many Heavy-lift forklifts can you replace?\n\n"
          "Please note: Only forklifts that have greater than 8,000 lbs. of lift capacity will qualify for this incentive.\n"
          "**Forklifts do  NOT need to be located at a port or airport to be eligible.**")
    forklift_count = input("Enter in # of forklifts:")
    if type(forklift_count) is int:
        fl_count = forklift_count
    else: 
        print("Invalid number. Please try again.")    
        data_grab()                       

Currently, when the user actually types in an integer, it will automatically jump to ELSE instead of executing the code under IF.

Any thoughts?

Aucun commentaire:

Enregistrer un commentaire