Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #55052
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; ';-)': 0.03; 'else:': 0.03; 'elif': 0.05; 'subject:Python': 0.06; 'tries': 0.07; 'string': 0.09; '34,': 0.09; '__name__': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; 'random': 0.14; '"your': 0.16; "'__main__':": 0.16; 'concatenate': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'silly': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'number)': 0.24; 'progress.': 0.24; 'replace': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'correct': 0.29; 'am,': 0.29; 'statement': 0.30; 'that.': 0.31; 'high.': 0.31; 'file': 0.32; '(most': 0.33; 'guess': 0.33; 'objects': 0.35; 'there': 0.35; 'thanks': 0.36; 'too': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'received:173': 0.61; 'making': 0.63; 'email addr:gmail.com': 0.63; 'number:': 0.66; "'you": 0.84; 'guessed': 0.84; 'received:fios.verizon.net': 0.84; 'mistake': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Python Unit Tests |
| Date | Mon, 30 Sep 2013 02:08:17 -0400 |
| References | <bb6482de-ce4e-4dd2-845c-f71008123c03@googlegroups.com> <mailman.431.1380394053.18130.python-list@python.org> <0dfb1b91-766c-47d5-9708-84b88838d247@googlegroups.com> <5248e816$0$2865$c3e8da3$76491128@news.astraweb.com> <d239fcf5-5730-4017-969d-bd6362a521d1@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-173-75-251-66.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
| In-Reply-To | <d239fcf5-5730-4017-969d-bd6362a521d1@googlegroups.com> |
| 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.474.1380521312.18130.python-list@python.org> (permalink) |
| Lines | 69 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1380521312 news.xs4all.nl 15877 [2001:888:2000:d::a6]:56188 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:55052 |
Show key headers only | View raw
On 9/30/2013 12:19 AM, melwin9@gmail.com wrote:
> Hi Dave,
>
> Yeah I found the silly mistake lol thanks for that. making progress.
>
>
> Guess a number: 5
> That's too high.
> Guess a number: 4
> That's too high.
> Guess a number: 3
> Traceback (most recent call last):
> File "guess.py", line 34, in <module>
> main(random.randint(1, 10))
> File "guess.py", line 29, in main
> print(responseCorrect + '! You guessed my number in ' + tries + 'guesses!')
> TypeError: cannot concatenate 'str' and 'int' objects
This is what 'untested' means ;-)
> [code]import random
>
> intro = 'I have chosen a number from 1-10'
> request = 'Guess a number: '
> responseHigh = "That's too high."
> responseLow = "That's too low."
> responseCorrect = "That's correct!"
> responseWrong = "Wrong, The correct number is "
> guessTaken = "Your number of guesses were "
> goodbye = ' Goodbye and thanks for playing!'
>
> allowed = 5
>
> def getguess(target, allowed):
> tries = 0
> while tries < allowed:
> tries += 1
> guess = int(input(request))
> if guess < target:
> print(responseLow)
> elif guess > target:
> print(responseHigh)
> else:
> return guess, tries
>
> def main(target):
> guess, tries = getguess(target, allowed)
> if guess == target:
> print(responseCorrect + '! You guessed my number in ' + tries + 'guesses!')
Either change 'tries' to 'str(tries)' or replace the statement with
print(responseCorrect, 'You guessed my number in', tries,
'guesses!')
There is no need to create a single string before the print.
> else:
> print(goodbye + ' The number I was thinking of was ' + number)
ditto
>
> if __name__ == '__main__':
> main(random.randint(1, 10)) [/code]
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python Unit Tests melwin9@gmail.com - 2013-09-27 21:52 -0700
Re: Python Unit Tests Dave Angel <davea@davea.name> - 2013-09-28 06:11 +0000
Re: Python Unit Tests Terry Reedy <tjreedy@udel.edu> - 2013-09-28 14:47 -0400
Re: Python Unit Tests melwin9@gmail.com - 2013-09-29 18:46 -0700
Re: Python Unit Tests Steven D'Aprano <steve@pearwood.info> - 2013-09-30 02:55 +0000
Re: Python Unit Tests melwin9@gmail.com - 2013-09-29 21:19 -0700
Re: Python Unit Tests Terry Reedy <tjreedy@udel.edu> - 2013-09-30 02:08 -0400
Re: Python Unit Tests melwin9@gmail.com - 2013-09-30 12:54 -0700
Re: Python Unit Tests MRAB <python@mrabarnett.plus.com> - 2013-09-30 21:08 +0100
Re: Python Unit Tests Dave Angel <davea@davea.name> - 2013-09-30 20:20 +0000
Re: Python Unit Tests Terry Reedy <tjreedy@udel.edu> - 2013-09-30 20:06 -0400
csiph-web