Python Forum
Missing an argument in function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Missing an argument in function
#1
im pretty sure i added that argument (item) and still getting this weird error .. >,<

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os

from collections import namedtuple
Item = namedtuple("Item", ['index', 'value', 'weight'])

def O(k , j ,  item):
   if j == 0 : #base case 
       return 0
   elif item[j-1].weight >= k :
       return max(O(k,j-1,item) , item[j-1].value + O(k-item[j-1].weight,j-1,item))
   else:
       return O(k,j-1)



items = []
items.append(Item(1,8,4))
items.append(Item(2,10,5))
items.append(Item(3,15,8))
items.append(Item(4,4,3))


x= O(11,4,item = items)

print(x)
Reply
#2
return o(k, j-1)
is missing the third argument
you are creating a recursive call to O here (before that actual return), and o requires 3 arguments

you must either supply one, or set a default value like:
def O(k , j ,  item=1):
In any case, it's bad practice to use single letter names. Hard to read, gives no indication of what it does, and leads to errors.
Reply
#3
Thanks man <3 ..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 471 Dec-15-2023, 02:00 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,073 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,838 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  TypeError: missing a required argument: 'y' gible 0 2,903 Dec-15-2021, 02:21 AM
Last Post: gible
  Regex - Pass Flags as a function argument? muzikman 6 3,578 Sep-06-2021, 03:43 PM
Last Post: muzikman
  TypeError: run_oracle_job() missing 1 required positional argument: 'connection_strin python_student 1 1,963 Aug-06-2021, 08:05 PM
Last Post: SheeppOSU
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 5,453 Jan-06-2021, 04:25 PM
Last Post: Insen
  How to use a tuple as an argument of a function zarox 5 3,577 Nov-14-2020, 08:02 PM
Last Post: buran
  calling a function and argument in an input phillup7 3 2,610 Oct-25-2020, 02:12 PM
Last Post: jefsummers
  Passing argument from top-level function to embedded function JaneTan 2 2,238 Oct-15-2020, 03:50 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