Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74393 > unrolled thread

codingbat question broken?

Started byRodrick Brown <rodrick.brown@gmail.com>
First post2014-07-12 22:05 -0400
Last post2014-07-12 22:05 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  codingbat question broken? Rodrick Brown <rodrick.brown@gmail.com> - 2014-07-12 22:05 -0400

#74393 — codingbat question broken?

FromRodrick Brown <rodrick.brown@gmail.com>
Date2014-07-12 22:05 -0400
Subjectcodingbat question broken?
Message-ID<mailman.11781.1405217673.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I'm working on the following problem set from codingbat.com

http://codingbat.com/prob/p107863

Given 3 int values, a b c, return their sum. However, if one of the values
is 13 then it does not count towards the sum and values to its right do not
count. So for example, if b is 13, then both b and c do not count.

lucky_sum(1, 2, 3) → 6
lucky_sum(1, 2, 13) → 3
lucky_sum(1, 13, 3) → 1

The solution I came up with was -

def lucky_sum(a, b, c):
  t = 0
  for ints in (a, b, c):
    if a == 13:
      t = b + c
    elif b == 13:
      t = a
    elif c == 13:
      t = a + b
    else:
      t = a + b + c
  return t

However the following tests fail

lucky_sum(13, 2, 3) → 05X     lucky_sum(13, 2, 13) → 015X    lucky_sum(13,
13, 2) → 015X

Can anyone show me an example where all test are success?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web