• Register
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.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes
 
Best answer

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

This may help you. Good Day!

13 9 6
94,260 points

Related questions

1 vote
1 answer 17 views
17 views
Problem: Any clue to fix this issue? Python non default argument follows default argument.
asked Apr 1 PkGuy 23.5k points
1 vote
1 answer 72 views
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.
asked Jun 7, 2020 samhaz 5k points
0 votes
1 answer 56 views
56 views
Problem: How to fix this: Syntaxerror: non-default argument follows default argument
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 9 views
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!
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 80 views
0 votes
1 answer 88 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
asked Mar 23 ummesalma 29.2k points
0 votes
1 answer 1.3K views
0 votes
1 answer 3 views
3 views
Problem: May I know how it can be resolved? > The distance a vehicle travels can be calculated as follows
asked 5 days ago Irenka Kiri 17.9k points
0 votes
1 answer 4 views
4 views
Problem: Given the names and grades for each student in a Physics class of students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade. Note: If there are multiple students with the same grade, order their names alphabetically and print each name on a new ... : >>[['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
asked Apr 26 anika11 32.2k points
0 votes
1 answer 16 views
16 views
Problem: I have a list of dataframes that all have identical numbers of columns (and rows). I want to bind them using purrr::map_df. I try map_df(my_list) and get Error in as_mapper(.f, ...) : argument ".f" is missing, with no default I'm not sure what's wrong with my list. It looks good to me (each dataframe has a unique name).
asked May 1 anika11 32.2k points