Another way to solve Unit 2.21 biggest

1
1

Here's the way I did it.'

def biggest(a,b,c):
        z=a
        if b>z: z=b
        if c>z: z=c
        return z

    print biggest(5,23,8)

``Here's the way I did it.

print z

asked 04 Mar '12, 21:35

Thomas%20Braniff's gravatar image

Thomas Braniff
1091713
accept rate: 0%

retagged 16 Jan, 09:00

Retagbot's gravatar image

Retagbot ♦
1518171

Would you please format your code by selecting it in the editor and clicking on the button labelled 101010? Thanks!

(04 Mar '12, 22:04) pmoriarty pmoriarty's gravatar image

6 Answers:

As I was thinking about it I came up with this one:

def bigger(a,b):
    if a > b:
        return a
    return b

def biggest(a, b, c):
    return bigger(a, bigger(b, c))
link

answered 04 Mar '12, 22:20

pmoriarty's gravatar image

pmoriarty
5.5k52377

1

Me like! :-)

(04 Mar '12, 22:25) Rafael Esper... Rafael%20Espericueta's gravatar image

Another solution, though perhaps using stuff not yet covered:

def biggest(a,b,c):
    L = [a,b,c]
    L.sort()
    return L[2]
link

answered 04 Mar '12, 22:14

Rafael%20Espericueta's gravatar image

Rafael Esper...
12.8k66128192

edited 04 Mar '12, 22:23

Here's how I did it:

def biggest(a, b, c):
    if a > b:
        if a > c:
            return a
    else:
        if b > c:
            return b
        else:
            return c
    return c
link

answered 04 Mar '12, 22:05

pmoriarty's gravatar image

pmoriarty
5.5k52377

Just to add to the mix...

def biggest(a, b, c):
if (a < b) or (a < c):
if (b < c):
return c
else:
return b
else:
return a

link

answered 04 Mar '12, 22:28

dedos's gravatar image

dedos
1.4k132230

What dedos said. :)

a = 45
b = 355
c = 2

def biggest(a, b, c):
    if a > b and a > c:
        return a
    if b > a and b > c:
        return b
    if c > a and c > b:
        return c
link

answered 04 Mar '12, 22:28

James%20Viebke's gravatar image

James Viebke
1.5k21831

Same as Mainframe, except reusing a:

def biggest(a,b,c):
    if a < b:
        a = b
    if a < c:
        a = c
    return a

print biggest(1,2,3)
print biggest(2,3,1)
print biggest(3,1,2)
link

answered 07 Mar '12, 11:42

tcabeen's gravatar image

tcabeen
111

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • 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,284
×70

Asked: 04 Mar '12, 21:35

Seen: 347 times

Last updated: 07 Mar '12, 11:42