Jump to content

Python how can I allow a function to accept a blank argument?

import turtle as tdef draw_space(x):    t.seth(360)    t.penup()    if x == '':        t.forward(50)        t.pendown()    else:        t.forward(x)        t.pendown()

This is using the turtle module just for an example here, but when I call the function such as so:

draw_space()

I want it to default to going forward by 50. However, If I run this, I get the error

TypeError: draw_space() missing 1 required positional argument: 'x'

But then if the parameter isn't left blank I want it to go forward, x. Ideas?

Link to post
Share on other sites

def draw_space(x):    t.seth(360)    t.penup()    if x == '\0':        t.forward(50)        t.pendown()    else:        t.forward(x)        t.pendown()

Does the same thing

use null parameter

OFF TOPIC:聽I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to post
Share on other sites

def draw_space(x):    t.seth(360)    t.penup()    if x == '\0':        t.forward(50)        t.pendown()    else:        t.forward(x)        t.pendown()

Does the same thing

try "if !x"

Don't ask to ask, just ask... please聽馃え

sudo chmod -R 000 /*

Link to post
Share on other sites

Just says invalid syntax for me, I'm doing something wrong.

sorry, I misread the question :P what you're doing wrong is very simple: you aren't passing any argument on to the function. You can't call draw_space() without passing it the "x" argument. calling draw_space(' ') with the original code should do the trick.

Don't ask to ask, just ask... please聽馃え

sudo chmod -R 000 /*

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now