On Aug 6, 2017 11:00 AM, <tutor-requ...@python.org> wrote:

Send Tutor mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."

Today's Topics:

   1. Re: unorderable types (Cameron Simpson)

---------- Forwarded message ----------
From: Cameron Simpson <c...@cskk.id.au>
To: tutor@python.org
Date: Sun, 6 Aug 2017 17:40:02 +1000
Subject: Re: [Tutor] unorderable types
On 06Aug2017 07:19, Alan Gauld <alan.ga...@yahoo.co.uk> wrote:

> On 05/08/17 19:28, Howard Lawrence wrote:
>>     if guess_value != number:
>>         number = str(number)
>>         print ('nope. the number i was thinking of was ' + number)
> There is the problem, you convert number to a str before printing
> it. so next iteration of the loop your if test fails.
> You don't need the conversion in this case because print does it
> automatically.

I should point out that print doesn't magicly let you "+" a str and an int.
You would need to write:

 print ('nope. the number i was thinking of was ', number)

You can see that that doesn't use "+". The print function calls str() on
each of its arguments, then writes the result to the output. str() on the
string returns itself, and str(number) returns the number in text form.

You can see then that you don't need str(number) yourself, and therefore do
not need to store it in a variable.

Also, while you can bind a value of any type to any variable, as you have
here by binding an int to "number" and then later a str to "number", it is
not a great idea. A particular variable should usually always hold the same
type of value; this storing of different types of values in the same
variable contributed to your problem.

Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)

Thanks for everything,it's running

     saw where storing two different types in the same variable!
   Digesting your pointers !

Tutor maillist  -  Tutor@python.org
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:

Reply via email to