Return Statement Dilemma

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2009
Posts: 112
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 9
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster

Return Statement Dilemma

 
0
  #1
Sep 9th, 2009
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 931
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 216
Gribouillis's Avatar
Gribouillis Gribouillis is online now Online
Posting Shark

Re: Return Statement Dilemma

 
1
  #2
Sep 9th, 2009
I'm putting some comments in your code, in dive into python's way
  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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC