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: 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 Subject: Re: Python Unit Tests Date: Mon, 30 Sep 2013 02:08:17 -0400 References: <0dfb1b91-766c-47d5-9708-84b88838d247@googlegroups.com> <5248e816$0$2865$c3e8da3$76491128@news.astraweb.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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 > 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