I'm trying to pass a dictionary to a function called solve_slopeint() using **kwargs because the values in the dictionary could sometimes be None depending on the user input. When I try to do that, I get a TypeError saying:
solve_slopeint() takes 0 positional arguments but one was given
Here's the whole process of what's happening:
Here is the code that you need to see:
main.py
def slope_intercept():
arg_dict = {
"point1": None,
"point2": None,
"slope": None,
"y-intercept": None
}
while True:
question1 = input("Were you given any points that the line passes through? (y/n): ")
if question1 == 'y':
point_list = passing_points()
if len(point_list) == 2:
arg_dict["point1"] = point_list[0]
arg_dict["point2"] = point_list[1]
solve_slopeint(arg_dict)
functions.py
def passing_points():
while True:
num_points = input("How many points were you given?: ")
try:
num_points = int(num_points)
elif num_points == 2:
point1_list = []
point2_list = []
while True:
point1 = input("Enter point 1 in the format x,y: ")
while True:
point2 = input("Enter point 2 in the format x,y: ")
return [point1_list, point2_list]
solve_functions.py
def solve_slopeint(**kwargs):
print("Equation solved!")
Click Here to see the output of the debugger in PyCharm.
Just so people know, I left out a lot of error checking making sure that the user doesn't intentionally or accidentally input something wrong. If I left out some code that makes this code here not understandable, please tell me in the comments.
Does anyone know how to fix this?
You're wrong calling the solve_slopeint
function.
Do it like this:
def slope_intercept():
arg_dict = {
"point1": None,
"point2": None,
"slope": None,
"y-intercept": None
}
while True:
question1 = input("Were you given any points that the line passes through? (y/n): ")
if question1 == 'y':
point_list = passing_points()
if len(point_list) == 2:
arg_dict["point1"] = point_list[0]
arg_dict["point2"] = point_list[1]
solve_slopeint(**arg_dict)
# Or:
# solve_slopeint(point1=point_list[0], point2=point_list[1])