Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74395
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <drsalists@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'element': 0.07; '__name__': 0.09; 'skip:# 30': 0.09; 'unmodified': 0.09; 'runs': 0.10; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; '2.7': 0.14; "'__main__':": 0.16; '(other': 0.16; '8bit%:32': 0.16; 'c):': 0.16; 'count.': 0.16; 'subject:broken': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'example': 0.22; 'email addr:gmail.com>': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'towards': 0.31; '13,': 0.31; 'assert': 0.31; 'anyone': 0.31; 'url:python': 0.33; 'problem': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'example,': 0.37; 'pm,': 0.38; 'does': 0.39; '12,': 0.39; 'url:mail': 0.40; 'skip:\xc2 10': 0.60; 'break': 0.61; 'show': 0.63; 'sum': 0.64; 'to:addr:gmail.com': 0.65; '8bit%:100': 0.72; 'jul': 0.74; '13)': 0.84; '13:': 0.84; 'sum.': 0.84; '-\xc2\xa0': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=v/y2exK8/fC74SLeLgG853t7842LEqPQSMBOtrVQPfw=; b=VQE54qvmBGtRR6mNDizaxm5SOR0V5ULvwSNjFvBxe4yCYpN7QbWGX/UBQyGSPjCSad 2c5K/9DgVMZfjFpWGQCwfawcbLa4YAl/x1StSjVTBKNKq1ZKVWrrDZTW51BfKK1bHwfx +1Jo7MN29O5YLIk9i9aBa9X2gQUMHanNe4Y+WPtMK8u4tgF7wr/J+1vnGNJdH3IJOj9k 47JJRKV9q2//TpLLzdgBlPh23sdWRDQ+zPpoR/WTjzdbjjnG/ajfXgLblgAHW+CZG5/1 jxc6tW32yPbsVPhCOuFH5xsPGrvTL2ACjUmw46urTTtEwqMJw/uM1Ye7tfZoVl5qUQEe kMBQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.252.226 with SMTP id zv2mr7078429vdc.19.1405225305518; Sat, 12 Jul 2014 21:21:45 -0700 (PDT) |
| In-Reply-To | <CABRP1o_xZYrojpjpT6u11jM1TTOp6aPBELsF4oYo3CLdeFLzZA@mail.gmail.com> |
| References | <CABRP1o_xZYrojpjpT6u11jM1TTOp6aPBELsF4oYo3CLdeFLzZA@mail.gmail.com> |
| Date | Sat, 12 Jul 2014 21:21:45 -0700 |
| Subject | Re: codingbat question broken? |
| From | Dan Stromberg <drsalists@gmail.com> |
| To | Rodrick Brown <rodrick.brown@gmail.com> |
| Content-Type | multipart/alternative; boundary=001a1135ed222a368404fe0b8370 |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11783.1405225308.18130.python-list@python.org> (permalink) |
| Lines | 185 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1405225308 news.xs4all.nl 2853 [2001:888:2000:d::a6]:52833 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74395 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
This runs on 2.7 or 3.4, unmodified (other than the #!):
#!/usr/local/cpython-2.7/bin/python
#!/usr/local/cpython-3.4/bin/python
def lucky_sum(*list_):
lucky_total = 0
for element in list_:
if element == 13:
break
lucky_total += element
return lucky_total
if __name__ == '__main__':
print('starting tests')
assert lucky_sum(1, 2, 3) == 6
assert lucky_sum(1, 2, 13) == 3
assert lucky_sum(1, 13, 3) == 1
print('ending tests')
On Sat, Jul 12, 2014 at 7:05 PM, Rodrick Brown <rodrick.brown@gmail.com>
wrote:
> 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?
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: codingbat question broken? Dan Stromberg <drsalists@gmail.com> - 2014-07-12 21:21 -0700
csiph-web