0

I made this code in PYTHON 2.7.17:

class prt(object):
    def _print(self, x):
        self.x = x
        print x
    def Write_turtle(self, shape, move=False, text_of_show, font=('Arial', 16, 'bold')):
        try:
            x.shape(shape)
            x.write(text_of_show, move, font)
        except:
            from turtle import *
            x = Turtle()
            x.shape(shape)
            x.write(text_of_show, move, font)

And it gave me this error at the end of line 5:

SyntaxError: non-default argument follows default argument

Can anyone help me? Thank you very much.

1

1 Answer 1

1

in your definition of Write_turtle the parameters move and font have default parameters. As the error message tells you, you have to put them at the end of the parameter list, e.g.:

def Write_turtle(self, shape, text_of_show, move=False, font=('Arial', 16, 'bold'))

The reason is, that these parameters are optional. If you do not set them, the default value is used. Because text_of_show has no default parameter, you always have to set it. This also implies, that you have to give all parameters before it a value. Therefore the default value for move is obsolete. If you call e.g.

Write_turtle((20, 10), True)

the interpreter would not know if the True is the value for move or for text_of_show. If you rearrange the parameters correctly as mentioned above you can call:

Write_turtle((20, 10), True)
Write_turtle((20, 10), False, True)

The first version sets move=False (its default value) the second one sets move=True.

For more information have a look at this!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but now I recive this error: SyntaxError: import * only allowed at module level (<pyshell#244>, line 6)
Now the problem is in the line: from turtle import * You should replace the * by the methods you really need. import * is only allowed at "top" level of your file structure. Another solution could be to move from turtle import * to the top of your file. Have a look at this post!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.