0

I'm quite new to programming, and the solution is probably easy, but if anybody could explain whats going on, it would mean heaps :)

code:

def loan (loan_amount,number_of_weeks):
    return (loan_amount/number_of_weeks)

loan_amount= int(input("Enter an amount: "))

number_of_weeks= int(input("Enter a number of weeks: "))


loan(loan_amount/number_of_weeks)

print ("you must repay",loan,"per week to repay a loan of",loan_amount,"in",number_of_weeks,"weeks")

error code:

Enter an amount: 5
Enter a number of weeks: 5
Traceback (most recent call last):
  File "C:/Users/Ethan/PycharmProjects/untitled1/Loan.py", line 7, in <module>
    loan(loan_amount/number_of_weeks)
TypeError: loan() missing 1 required positional argument: 'number_of_weeks'

2 Answers 2

2

You defined loan to take two arguments. So, you would have to call it like:

loan(loan_amount, number_of_weeks)

Heads up, you probably want to assign the result of that to a variable which you then later print. Printing loan prints the function object representation.

Sign up to request clarification or add additional context in comments.

Comments

0

yup, in your call to loan() you have a slash where you should have a comma.

loan(loan_amount/number_of_weeks)

should be

loan(loan_amount,number_of_weeks)

also, in the next line, you print "loan", but that's not set to anything. You can either set the output of loan to a variable:

loan_var = loan(loan_amount/number_of_weeks)
print ("you must repay",loan_var,"per week to repay a loan of",loan_amount,"in",number_of_weeks,"weeks")

or call it directly in the print statement:

print ("you must repay",loan(loan_amount/number_of_weeks),"per week to repay a loan of",loan_amount,"in",number_of_weeks,"weeks")

2 Comments

I added in the "loan_var" variable, bit still getting an error message. loan(loan_amount,number_of_weeks) loan_var = loan(loan_amount/number_of_weeks) print ("you must repay",loan_var,"per week to repay a loan of",loan_amount,"in",number_of_weeks,"weeks") error Enter an amount: 100 Enter a number of weeks: 5 Traceback (most recent call last): File "C:/Users/Ethan/PycharmProjects/untitled1/Loan.py", line 8, in <module> loan_var = loan(loan_amount/number_of_weeks) TypeError: loan() missing 1 required positional argument: 'number_of_weeks'
Don't forget to replace the slash with a comma inside loan(). That's what's causing this particular error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.