Python Forum
TypeError: add() missing 2 required positional arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: add() missing 2 required positional arguments
#1
Hello,I am new to parameters and I am having difficulties understanding my code does not work.




# Tables

Table_A = 0
Table_B = 0
Table_C = 0

# Seats remaining

seat_A = 4
seat_B = 6
seat_C = 2

def add(user_In,Table,Seat):
    for i in range(user_In):
        Table += 1
        Seat -= 1
    return(Table)

def sit():
    global Table_A, Table_B, Table_C, seat_A, seat_B, seat_C
    while True:
        time.sleep(1)
        # Showing Tabls
        print("\nShowing Tables\n")
        time.sleep(1)
        # Table A
        print("Table - A has -", (Table_A), "- people / -", (seat_A), "- seats remaining")
        # Table B
        print("Table - B has -", (Table_B), "- people / -", (seat_B), "- seats remaining")
        # Table C
        print("Table - C has -", (Table_C), "- people / -", (seat_C), "- seats remaining\n")
        time.sleep(1)
        # User Input
        user_In = input ("Which table would you like to choose: ")
        user_In = user_In.upper()
        if user_In == "A":
            Table = Table_A
            Seat = seat_A
            time.sleep(1)
            user_In = int(input("How many people are sitting? Max -" + str(Seat) + ": "))
            # Table A Returned
            print("\nTable - A has - " , add(user_In), "- in it") 
Reply
#2
You have defined your add() function to expect 3 arguments (user_In, Table, Seat), but you are calling it with only a single argument in line 42.
Reply
#3
(May-28-2020, 12:33 PM)GOTO10 Wrote: You have defined your add() function to expect 3 arguments (user_In, Table, Seat), but you are calling it with only a single argument in line 42.
Thank you! That makes sense!
Reply
#4
I don't know the scope of your program but, just wanted to point out that these are already global variables. Not really any need to define them global in your functions.

myvar = 15

def test():
    print(myvar)

test()
Output:
15
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
Gaming Collection
Homepage
my-python
Reply
#5
(May-28-2020, 12:54 PM)menator01 Wrote: I don't know the scope of your program but, just wanted to point out that these are already global variables. Not really any need to define them global in your functions.

myvar = 15

def test():
    print(myvar)

test()
Output:
15
You are right there is no need for the global variables! Previously I would get an error that said something like "local variable not called" but I guess for this I do not need it, thanks for the advice.
Reply
#6
Look at your last chunk of code:


print("\nTable - A has - " , add(user_In), "- in it")


when you call add(user_In) you only enter 1 parameter, when you are supposed to enter 3.
you could alter the function to receive to default to a certain value.

for example when defining the function,

def add(value = deafult) instead of def add(value)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python 3: TypeError: a bytes-like object is required, not 'str' wardancer84 3 253 Jul-09-2021, 05:55 PM
Last Post: deanhystad
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 1,600 May-15-2021, 04:15 PM
Last Post: Anldra12
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 822 Jan-06-2021, 04:25 PM
Last Post: Insen
  TypeError: a bytes-like object is required, not 'str' ozzy69 1 799 Jul-17-2020, 03:38 PM
Last Post: stullis
  How to reuse positional arguments entered in terminal. rcmanu95 1 590 Jul-04-2020, 01:00 AM
Last Post: bowlofred
  Missing 1 required position argument: 'failure' while starting thread. BradLivingstone 3 1,023 Jun-19-2020, 02:31 PM
Last Post: stullis
  TypeError: forward() missing 1 required positional argument: 'x' sveto4ka 4 3,379 Jun-17-2020, 07:25 PM
Last Post: sveto4ka
  Packet Sniffer - TypeError: a bytes-like object is required, not 'str' cheffa2020 4 1,469 Jun-12-2020, 02:10 PM
Last Post: cheffa2020
  missing 1 required positional argument: 'self' yasser 7 4,324 Jun-07-2020, 06:48 AM
Last Post: ndc85430
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 3,061 May-31-2020, 03:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020