mercredi 16 juin 2021

How to run a function with no parameters defined?

I am trying to create a code that does not require parameters to determine if one is qualified for a loan, but the function takes years and annual wage into account to determine if qualified. How do I get the function input that would still allow the main program to work?

edit: I cannot give it parameters becausse that is what was asked of me. To create this function without parameters.

def loan():
    """
    -------------------------------------------------------
    To qualify for a loan, the annual salary must be 30000 or more and  
    employee must have worked for a minimum of 5 years
    Use: qualified = loan()
    -------------------------------------------------------
    Returns:
        qualified - True if employee qualifies for a loan,
            False otherwise (boolean)
    -------------------------------------------------------
    """
    MIN_SALARY =30000
    MIN_YEARS = 5
    if years < 5:
        qualified = False 
    elif years >= MIN_YEARS:
        if salary >= MIN_SALARY:
            qualified = True 
        else: 
            qualified = False 
    else:
        qualified = False 
    return qualified

#--------------Main Program-----------------#

years = int(input('Years employed: '))
salary = float(input('Annual salary: '))
qualified = loan(years = years, salary = salary)
print()
print('Qualified for a loan: {}'.format(qualified))

Aucun commentaire:

Enregistrer un commentaire