• Register
1 vote
42 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,240 points

Related questions

1 vote
1 answer 48 views
48 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 57 views
0 votes
1 answer 898 views
0 votes
1 answer 22 views
22 views
def choose_option(self): if self.option_picker.currentRow() == 0: description = open(":/description_files/program_description.txt","r") self.information_shower.setText(description.read()) elif self.option_picker.currentRow() == 1: requirements = open(":/description_files/ ... it as argument in open function, but when i am using it for loading of pictures and icons everything is fine.
asked Oct 24, 2020 psandprop 2.4k points
0 votes
1 answer 2 views
2 views
Problem: In core_test.py I have the following import statement from ..components.core import GameLoopEvents However, when I run, I get the following error: tests$ python core_test.py Traceback (most recent call last): File "core_test.py", line 3, in <module> from ..components.core import GameLoopEvents ValueError: Attempted relative import in non-package
asked 2 days ago Mashhoodch 9.1k points
0 votes
1 answer 20 views
20 views
Problem: I am typing to get a sale amount (by input) to be multiplied by a defined sales tax (0.08) and then have it print the total amount (sales tax times sale amount). I run into this error. Anyone know what could be wrong or have any suggestions?
asked Feb 14 Mashhoodch 9.1k points
0 votes
1 answer 18 views
18 views
Task: Read an integer N . For all non-negative integers i<N , print i2. if __name__ == '__main__': n = int(input()) if (n<=0) and (n>=20): print("Exit") else: for(i=0,i<=n,i++): print(i*i) I am getting below error File "solution.py", line 6 for(i=0,i<=n,i++): ^ SyntaxError: invalid syntax Exit Status 255
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 46 views
46 views
Hello house, I would like to know how to solve this Python SyntaxError: Non-ASCII character '\xe2' in file. Thanks
asked Oct 23, 2020 psandprop 2.4k points
0 votes
2 answers 278 views
278 views
Problem : While submitting the Python program i am getting below error python can't multiply sequence by non-int of type 'float'
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 224 views
224 views
Problem : I'm new to python and I've been struggling with this problem for a while. I've search google and youtube but no luck so far. I've written this in IDLE 2.6.5. If someone could tell me why I'm getting the can't multiply sequence by non-int of type float error.
asked Oct 21, 2019 peterlaw 6.9k points