unit 2.21 biggest quiz.. the submission mechanism is crap

def biggest(a,b,c):
    if a>b:
        grtr=a
    else:
        grtr=b
    if grtr > c:
        print grtr
    else:
        print c
biggest(1,2,3)

It works fine when u run it but gives an error when submitted..
works fine in Drpython too..:@@

asked 09 Mar '12, 02:20

Vipul%20Jhamnani-1's gravatar image

Vipul Jhamna...
26
accept rate: 0%

edited 09 Mar '12, 02:21

Rob%20Barnes-3's gravatar image

Rob Barnes-3 ♦
19.1k1068205


One Answer:

You're printing the values instead of returning them

link

answered 09 Mar '12, 02:22

Rob%20Barnes-3's gravatar image

Rob Barnes-3 ♦
19.1k1068205

so wats the big deal..
i should get it correct no matter how i submit the code..
this is BUG in their logic

(09 Mar '12, 02:26) Vipul Jhamna... Vipul%20Jhamnani-1's gravatar image
2

A BUG in their logic? Hmm.. not really.
If you were to write a real program, you would soon find out that print and return would make a big difference in expected behavior. And unlike what you seem to expect your teachers to do, I'm afraid a program will simply not read your mind and assume you meant return when you wrote print or meant print when you wrote return or whatever else for that matter.

(09 Mar '12, 03:13) Akuna Akuna's gravatar image

It is not a bug in their logic. It's a bug in yours.

If you have a function that is supposed to return something, and it doesn't, the program doesn't work.

Quick example:

def square(number):
    return number * number

x = 5
answer = 5 + square(x)
print answer

would exectute and the result of the program would be:

30

Change the return to a print:

def square(number):
    print number * number

x = 5
answer = 5 + square(x)
print answer

and you now have a program that doesn't work :p

So the moral of the story is, use return when you're supposed to return something, and print when you're supposed to print it.

'print' versus 'return': To print or Not to print May provide you with some guidance.

(09 Mar '12, 03:18) Rob Barnes-3 ♦ Rob%20Barnes-3's gravatar image
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,276
×236
×18

Asked: 09 Mar '12, 02:20

Seen: 89 times

Last updated: 09 Mar '12, 03:20