# Please clarify the explanation of Homework 2.2

 1 It has been mentioned that the original procedure and procedure-1 are equivalent i.e. Original procedure: def proc(a,b): if test(a): return b return a  Procedure #1: def proc1(x,y): if test(x): return y else: return x  Please clarify the following in this respect: Q: Can a Python procedure return two values? For example can it return both a and b? I am asking this because in the original procedure b is returned only if test(a) becomes true. On the other hand the statement "return a" is outside the if... condition. So it should execute anyway. Now if test(a) evaluates to false, only a is returned. But if test(a) evaluates to true then b is returned as well as a .... is my understanding correct or wrong? If so, how is Procedure #1 equivalent to the original procedure? It either returns x or y, depending on test(x), but not both. asked 07 Mar '12, 21:55 Santanu Acharya 51●6 accept rate: 133%

 2 A return automatically ends execution of the procedure and returns the parameters. So in that code there, ONLY b is returned if test(a) is true. the program never actually reaches the return a code. Also, yes, you can return multiple values, for example; return a,b,c answered 07 Mar '12, 22:01 Ioan-Victor ... 1.2k●4●15●41
 1 I think the first proc use the shortcut instead of else keyword?? I also think you can return two things like this: return a, b. I do not know for sure if you can return two things consecutively, like this: return a return b Because immediately the first return is reached, the second one will not be reached. Good luck. answered 07 Mar '12, 21:59 Eenvincible 3.6k●16●41●79
 0 Ok...I think I get it. Once a return statement is issued, the execution of the procedure stops and it exits (that's the general behavior of return in most other languages...which I forgot :( ). So, if two separate return statements are there, only one should execute. As for returning two variables in the same return statement, maybe that would work. I'd check. Thanks for replying. answered 07 Mar '12, 22:05 Santanu Acharya 51●6
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

### Tags:

×15,285
×74
×15

Asked: 07 Mar '12, 21:55

Seen: 109 times

Last updated: 07 Mar '12, 22:05