SyntaxError: positional argument follows keyword argument in Python

Dung Do Tien May 01 2022 368

Hello Guys, I'm a student and start to learn Python last month. I want to create a small function to help calculate the grade point average of students. like this:

def avg_point(math, physics, chemistry):
    return (math+physics+chemistry) / 3

m1 = int(input("enter math point: "))
m2 = int(input("enter physics point: "))
m3 = int(input("enter chemistry point: "))

result = avg_point(m1, physics = m2, m3)
print("your grade point average is ", result)

But when running the code above I got an exception SyntaxError: positional argument follows keyword argument

File "<string>", line 9
SyntaxError: positional argument follows keyword argument

I'm using Python 3.9 and Windows 11.

Thanks in advance.

Have 1 answer(s) found.
  • B

    Ba Một Hai May 01 2022

    You can use param name to help assign value but it has to be from right to left, not left to right. For example:

    result = avg_point(m1, m2, chemistry = m3)
    result = avg_point(m1, physics = m2, chemistry = m3)
    result = avg_point(math = m1, physics = m2, chemistry = m3)

    I hope this answer is useful for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close