On Aug 6, 2017 11:00 AM, <[email protected]> wrote:
Send Tutor mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
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 <[email protected]>
To: [email protected]
Cc:
Bcc:
Date: Sun, 6 Aug 2017 17:40:02 +1000
Subject: Re: [Tutor] unorderable types
On 06Aug2017 07:19, Alan Gauld <[email protected]> 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.
Cheers,
Cameron Simpson <[email protected]> (formerly [email protected])
Thanks for everything,it's running
saw where storing two different types in the same variable!
Digesting your pointers !
_______________________________________________
Tutor maillist - [email protected]
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor