0

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 can I get the function to take inputs without parameters?

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))
Ahri
  • 15
  • 2
  • 4
  • 4
    Why not just give `loan` parameters? If it takes arguments, it needs parameters. – Carcigenicate Jun 16 '21 at 16:23
  • 2
    If you use a class you can use self.money or self.min_salary. Then you can have a class method that only takes in one "parameter," self – Peter Jones Jun 16 '21 at 16:23
  • I'm not sure why you don't just add those parameters, but this could possibly help https://stackoverflow.com/questions/1769403/what-is-the-purpose-and-use-of-kwargs – Chris Jun 16 '21 at 16:24
  • 1
    There is not a reproducible problem here. "How do I do things in the poorly-designed way that my instructor wants me to do them?" is not on topic for Stack Overflow. – Karl Knechtel Jun 16 '21 at 18:03

2 Answers2

1

You could use keyword args for this...

def loan(**kwargs):
    ...

...but the more sensible and practical thing would be to specify the parameters you expect to be passed into the function.

def loan(years, salary):
    ...

Methods aren't magical and they have their own scope. If you don't add variables to that scope, then the only way you'd get information is from global scope, which is expressly discouraged and also wholly unnecessary in this case.

Makoto
  • 104,088
  • 27
  • 192
  • 230
0

I was able to figure it out. What I did was add the inputs into the code itself.

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)
    -------------------------------------------------------
    """
    years =(int(input('Years employed: ')))
    salary = (float(input('Annual salary: ')))
    #rest of the function
Ahri
  • 15
  • 2
  • 4
  • 2
    I'm sure that meets the requirements of the exercise, but it is very poor design. Separation of input from calculation is a very basic modularization technique. – BoarGules Jun 16 '21 at 18:14
  • Yes, ideally, functions should just take and return data. Functions that handle their own acquisition of data are harder to test and reuse. – Carcigenicate Jun 17 '21 at 12:35