| | |
Return Statement Dilemma
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
I'm stumped on this one and I've done lots of experimenting, help would be appreciated.
Python Syntax (Toggle Plain Text)
def next_block(x): p1 = 2 p2 = 2.3 p3 = "c" p4 = "String" p5 = "3.4444" return p1, p2, p3, p4, p5, print (x) next_block("testing") p1, p2, p3, p4, p5 = next_block() print (p1) print (p2) print (p3) print (p4) print (p5) input()
I'm stumped on this one and I've done lots of experimenting, help would be appreciated.
I'm putting some comments in your code, in dive into python's way
python Syntax (Toggle Plain Text)
def next_block(x): # [1] ... return p1, p2, p3, p4, p5, print (x) # [2] next_block("testing") # [3] p1, p2, p3, p4, p5 = next_block() # [4] """ [1] This function declares the argument x. It must be called with exactly 1 argument. Correct. [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. [3] Here you call next_block, but you don't do anything with the returned tuple which is lost. It's OK. [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. """
Last edited by Gribouillis; Sep 9th, 2009 at 3:15 am.
![]() |
Similar Threads
- missing return statement (Java)
- Keep getting 'Missing Return Statement' error (Java)
- Missing return Statement (Java)
- missing return statement (Java)
- missing return statement (Java)
- missing return statement 106 and 123, any ideas?? (Java)
Other Threads in the Python Forum
- Previous Thread: My python program/function!
- Next Thread: Parse some data from a password protected site [UPDATED]
| Thread Tools | Search this Thread |
alarm assignment avogadro beginner bluetooth character cmd code customdialog cx-freeze data decimals dictionary directory dynamic error examples exe file float format function generator getvalue gnu graphics gui halp homework http ideas import input ip itunes java leftmouse line linux list lists logging loop maintain maze millimeter module mouse number numbers output parsing path port prime programming projects push py2exe pygame pyglet pyqt python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tlapse tuple tutorial ubuntu unicode urllib urllib2 variable variables ventrilo verify vigenere web webservice wikipedia wxpython xlib





