943,929 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 440
  • Python RSS
Sep 9th, 2009
0

Return Statement Dilemma

Expand Post »
Okay, so, my main problem here, is that I can't get my parameters from my function name to work with the other variables from the function. Here's the code:

Python Syntax (Toggle Plain Text)
  1. def next_block(x):
  2. p1 = 2
  3. p2 = 2.3
  4. p3 = "c"
  5. p4 = "String"
  6. p5 = "3.4444"
  7.  
  8. return p1, p2, p3, p4, p5, print (x)
  9.  
  10. next_block("testing")
  11. p1, p2, p3, p4, p5 = next_block()
  12.  
  13. print (p1)
  14. print (p2)
  15. print (p3)
  16. print (p4)
  17. print (p5)
  18. input()

I'm stumped on this one and I've done lots of experimenting, help would be appreciated.
Similar Threads
Reputation Points: 14
Solved Threads: 17
Junior Poster
AutoPython is offline Offline
138 posts
since Sep 2009
Sep 9th, 2009
1

Re: Return Statement Dilemma

I'm putting some comments in your code, in dive into python's way
python Syntax (Toggle Plain Text)
  1. def next_block(x): # [1]
  2. ...
  3. return p1, p2, p3, p4, p5, print (x) # [2]
  4.  
  5. next_block("testing") # [3]
  6. p1, p2, p3, p4, p5 = next_block() # [4]
  7.  
  8. """
  9. [1] This function declares the argument x. It must be called with exactly 1 argument. Correct.
  10. [2] The function returns a tuple with 6 elements. The last element is the return value of the expression print(x), which is always None. No error.
  11. [3] Here you call next_block, but you don't do anything with the returned tuple which is lost. It's OK.
  12. [4] 2 errors here: you call next_block without arguments, which contraditcs the function's signature (how it must be called), and you try to assign 5 values from the returned tuple, which won't work because the returned value has length 6.
  13. """
Last edited by Gribouillis; Sep 9th, 2009 at 3:15 am.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: My python program/function!
Next Thread in Python Forum Timeline: Parse some data from a password protected site [UPDATED]





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC