omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Newbie to coding trying to use list item as argument in a function

    Pythonista
    2
    3
    1321
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • danaportenier
      danaportenier last edited by

      Sorry for likely simple questions but cant seem to find the answers and the group was awesome with my last simple question. Amazing how much time can be spent looking for answer. Ive certainly spent plenty on this one. Learned a lot in the process of looking but cant find my specific answer

      I just have a simple list and want to use an individual item from the list as an arguement in a function when I call the function.

      Error is “list() takes at most 1 argument (6 given)

      I have tried many variations of this trying to get it correct. Below I have pasted current form of code.

      Abbreviated Code below (weight_lbs and ideal_body_wt are calculated by other functions assigned to a variable and passed to this function):

      percent = list(40, 50, 55, 60, 70, 80)

      def Weight_After_PercentageEWL(percent, weight_lbs, ideal_body_wt):
      x = weight_lbs - (percent * ideal_body_wt)
      weight_after_percentewl = Weight_After_PercentageEWL(percent, weight_lbs, ideal_body_wt)

      print('With Sleeve Gastrectomy patients lose between 40% and 60% Excess Weight Loss. This would put your weight between ' + str(Weight_After_PercentageEWL(percent[0], weight_lbs, ideal_body_wt)) + ' and ' + str(Weight_After_PercentageEWL(percent[3] , weight_lbs, ideal_body_wt)))

      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @danaportenier last edited by

        @danaportenier, list init needs a list, not several values. Thus you could say:

        percent = list([40, 50, 55, 60, 70, 80])
        

        But this is just redundant (giving a list to list to create a list), so this is sufficient:

        percent = [40, 50, 55, 60, 70, 80]
        

        A reminder on the best practices when getting advice from the forum:

        • Enclose code into three back-ticks (select code, then click the </> above the edit field)

        • Share also at least the line number of the error, or preferably the whole stack trace

        1 Reply Last reply Reply Quote 0
        • danaportenier
          danaportenier last edited by

          Yes I used that option but was cycling through different option I found to try to be able to call an individual item in my print statement below. Thanks

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors