Homework 2.3: where is the mistake

 0 # Define a procedure, median, that takes three # numbers as its inputs, and outputs the median # of the three numbers. # Make sure your procedure has a return statement. def bigger(a,b): if a > b: return a else: return b def biggest(a,b,c): return bigger(a,bigger(b,c)) def median(a, b, c): h = biggest(a, b, c) if h==a: x = b y = c if h==b: x = a y = c else: x = a y = b return bigger(x, y) print median (7,8,7)  asked 08 Mar '12, 13:07 Navneet Vish... 10●3 accept rate: 50% Rob Barnes-3 ♦ 19.1k●10●68●205 When you post code, you want to make sure it's formatted properly so we can read it. Please review this post if you need to know how to format your code for the forums. (08 Mar '12, 23:22) Rob Barnes-3 ♦

 0 It doesn't work if the first number is the biggest. median(3,1,2) returns 3 answered 08 Mar '12, 13:10 Tim Gläßer 285●2●7
 0 yeah ... got it thanks Tim answered 08 Mar '12, 13:13 Navneet Vish... 10●3
 0 Please, format your code with 101010 button. It will be easier to read, and easier to find what's wrong. Thanks. answered 08 Mar '12, 13:14 macjohn 4.3k●9●33●72 I'll remember from next time (08 Mar '12, 23:21) Navneet Vish...
 0 I have the same issue...cant figure problem with my solution.. answered 08 Mar '12, 13:20 nty 24●5 you have to either return after condition statement or make the second one as 'elif' the problem is .... even if the first condition is true, being second condition false, else statement is changing the value and producing wrong result for every test case where first condition holds true. (08 Mar '12, 23:24) Navneet Vish...
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,219
×1,718
×76
×43

Asked: 08 Mar '12, 13:07

Seen: 216 times

Last updated: 08 Mar '12, 23:24