how to fix takes 0 positional arguments but 2 were given

When Python tells you "generatecode() takes 0 positional arguments but 1 was
given", it's telling you that your method is set up to take no arguments, but
the self argument is still being passed when the method is called, so in fact
it is receiving one argument.

Adding self to your method definition should resolve the problem.

5
1
Awgiedawgie 440220 points

                                    #-----import statements-----
import turtle as trtl
import random as rand

# creating diablo
diablo = trtl.Turtle("arrow")
diablo.shapesize(2)
diablo.fillcolor("pink")
score = 0

score_keeper = trtl.Turtle()
score_keeper.hideturtle()
score_keeper.penup()
score_keeper.goto(200,200)
score_keeper.pendown()  
counter = trtl.Turtle()
font_setup = ("Arial", 20, "normal")
timer = 5
counter_interval = 1000   #1000 represents 1 second
timer_up = False
counter.hideturtle()
counter.penup()
counter.goto(-10,200)

reset_button = trtl.Turtle("circle")
reset_button.penup()
reset_button.goto(-100,-100)


# making new x and y values for diablo
def scored():
    global score
    score += 1
    score_keeper.clear()
    score_keeper.write(score)

def change_position():
    a = rand.randint(-250,250)
    b = rand.randint(-250,250)
    diablo.penup()
    diablo.goto(a,b)

def countdown():
    global timer, timer_up
    counter.clear()
    if timer <= 0:
        counter.write("Time's Up", font=font_setup)
        timer_up = True
        diablo.hideturtle()
    else:
        counter.write("Timer: " + str(timer), font=font_setup)
        timer -= 1
        counter.getscreen().ontimer(countdown, counter_interval)

def reset_now(self):
    counter = 0
    score = 0
    diablo.showturtle()

# naming when diablo gets clicked then changing position
def diablo_clicked(x, y):
    scored()
    change_position()
    
diablo.onclick(diablo_clicked)
reset_button.onclick(reset_now)
wn = trtl.Screen()
wn.ontimer(countdown, counter_interval)
wn.bgcolor("#79F0FF") 
wn.mainloop()

5 (1 Votes)
0
4.4
5
Phoenix Logan 186120 points

                                    TypeError: method() takes 1 positional argument but 2 were given

4.4 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
takes 0 positional arguments but 2 were given TypeError: inputhc() takes 0 positional arguments but 2 were given takes 3 positional arguments but 4 were given get() takes 1 positional argument but 2 were given add() takes 2 positional arguments but 3 were given TypeError: show() takes 1 positional argument but 2 were given get() takes from 2 to 3 positional arguments but 5 were given execute() takes from 2 to 3 positional arguments but 4 were given TypeError: create() takes 1 positional argument but 3 were given takes 3 positional arguments but 4 were given python name() takes 0 positional arguments but 1 was given takes 0 positional arguments but 1 was given in python takes 1 positional argument but 2 were given python error isin() takes 2 positional arguments but 3 were given TypeError: function takes 1 positional arguments but 2 were given set_trace() takes 0 positional arguments but 1 was given python function takes 0 positional arguments but 1 was given takes 3 positional arguments but 4 were given TypeError: takes 5 positional arguments but 6 were given but i give 5 TypeError: method() takes 1 positional argument but 2 were given takes 0 positional arguments but 1 was given static start() takes 1 positional argument but 4 were given TypeError: build() takes 0 positional arguments but 1 was given size() takes 0 positional arguments but 4 were given method takes 0 positional arguments but 1 was given eat() takes 0 positional arguments but 1 was given run() takes 0 positional arguments but 1 was given TypeError: print() takes 0 positional arguments but 2 were given search() takes from 2 to 3 positional arguments but 8 were given TypeError: new_error() takes 2 positional arguments but 3 were given options() takes 1 positional argument but 3 were given update() takes 1 positional argument but 2 were given execute() takes from 2 to 4 positional arguments but 21 were given method() takes 1 positional argument but 2 were given create() takes 1 positional argument but 2 were given takes 2 positional arguments but 4 were given takes 0 positional arguments but 2 were given, even when i except 2 arguments deleteRec() takes 0 positional arguments but 1 was given TypeError: config() takes from 1 to 4 positional arguments but 5 were given TypeError: takes 6 positional arguments but 7 were given takes 0 positional arguments but 1 was given python TypeError: addLoad() takes 0 positional arguments but 8 were given takes from 1 to 3 positional arguments but 4 were given TypeError: function() takes 0 positional arguments but 1 was given __call__() takes 2 positional arguments but 3 were given send() takes 2 positional arguments but 4 were given takes 1 positional argument but 2 positional arguments fire() takes 1 positional argument but 2 were given python .validate() takes 0 positional arguments but 2 were given .validate_() takes 0 positional arguments but 2 were given takes 2 positional arguments but 3 were given TypeError: generate() takes 0 positional arguments but 1 was given takes 1 positional argument but 4 positional arguments (and 4 keyword-only arguments) were given TypeError: show_values() takes 0 positional arguments but 1 was given get_status() takes 1 positional argument but 2 were given TypeError: success() takes 2 positional arguments but 4 were given array() takes from 1 to 2 positional arguments but 4 were given open() takes 1 positional argument but 2 were given on_message() takes 1 positional argument but 2 were given show() takes 1 positional argument but 2 were given open() takes 0 positional arguments but 1 was given build() takes 2 positional arguments but 4 were given connect() takes 1 positional argument but 2 were given open() takes 0 positional arguments but 2 were given connect_error() takes 0 positional arguments but 1 was given python takes 0 positional arguments but 1 was given TypeError takes 0 positional arguments but 1 was given takes 1 positional argument but 3 were given python exec() takes 1 positional argument but 2 were given TypeError: test() takes 0 positional arguments but 1 was given add_argument() takes 2 positional arguments but 3 were given takes 0 positional arguments but 1 was given python error TypeError: value() takes 3 positional arguments but 4 were given takes 1 positional argument but 2 were given python takes 0 positional arguments but 1 was given update() takes 2 positional arguments but 3 were given calling function using positional arguments how to fix takes 0 positional arguments but 2 were given
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source