# Python non-default argument follows default argument

1 vote
50 views

## Problem:

I am trying to implement the Pythagorean formula in my program using a function. But the program is not running for some reason. I am attaching my code snippet and the error message below:

``````from math import sqrt
def pythagorean (a, b=-1, c):
return sqrt(a ** 2 + c ** 2)
pythagorean(a=3,c=9)``````

Error message:

``````  File "main.py", line 17
def pythagorean (a, b=-1, c):
SyntaxError: non-default argument follows default argument``````

As you can see in the error message, non-default argument follows default argument. What is this error? How can I fix the error? Thanks for your kind concern buddy.

## Solution:

As I can see, you have a non-default argument after the default argument inside your function

``def pythagorean (a, b=-1, c)``

the right way to write the function argument is:

``def pythagorean (a, c, b=-1)``

Moreover, you were wrong in your code on the line return function line. This is not gonna return anything. To fix the program, set all the arguments to default in your function. Now, the question could be, how do we know which two parameters are passed into the function? To make it sure we may have if-elf statement inside our function and end of the function we’ll get the result.

``````from math import sqrt
def pythagorean (a = -1, b = -1, c = -1):
if a == -1:
return sqrt(c**2 - b**2)
elif b == -1:
return sqrt(c**2 - a**2)
elif c == -1:
return sqrt(a**2 + b**2)
else:
return 0
pytho = pythagorean(a=3, c=9)
print pytho``````

## Related questions

1 vote
17 views
Problem: Any clue to fix this issue? Python non default argument follows default argument.
1 vote
72 views
Problem: I tried to pass the kwargs as a dictionary so I wrote this code: class All(object): otp_wait = 25 def __init__(self, surname, birthdate, mobile_no, otp_host, **kwargs): kwargs.setdefault('browser', 'chrome') self.surname = surname self. ... otp_host, **input_kwargs) ^ SyntaxError: positional argument follows keyword argument Can anyone help me out to solve this thing. Thanks in advance.
56 views
Problem: How to fix this: Syntaxerror: non-default argument follows default argument
9 views
Problem: I am calling a function in python. It is giving an error like this: Syntaxerror: positional argument follows keyword argument How to resolve this error? Thanks!
80 views
88 views
Problem: I'm trying to compile the same C file on two different machines with different versions of cc. gcc version 3.2.3 says warning: 'foo' was declared implicitly 'extern' and later 'static' gcc version 4.1.2 says error: static declaration of 'foo' follows non-static declaration