[Tutor] Issue with string method: str(variable ** n)

Rafael Knuth rafael.knuth at gmail.com
Thu May 16 21:26:01 CEST 2013


Thank you - that makes perfectly sense.

Also, I am new to the list, and I appreciate your suggestion.
I will include error tracebacks in the future.

All the best,
Rafael


On Thu, May 16, 2013 at 9:14 PM, Dave Angel <davea at davea.name> wrote:

> On 05/16/2013 02:58 PM, Rafael Knuth wrote:
>
>> Hej,
>>
>> I wrote a tiny little program which I was hoping would take a number as
>> input, square and print it:
>>
>> square = input ("Enter a number. ")
>> print (str(square) + " squared is " + str(square ** 2))
>>
>> It seems I can't work with variables within the str() string method, and I
>> was wondering if anyone can help?
>>
>> PS. I am using Python 3.3.0
>>
>> Thank you in advance!
>>
>> Rafael
>>
>>
>>  In Python 3.3.0, input returns a string.  So square is a string.  There
> isn't any meaning to squaring a string.
>
>
> You probably want either:
>
> square = float(input("Enter a number.")
> or
> square = int(input("Enter a number.")
>
> Suggestion for next time - include the error traceback.
>
> --
> DaveA
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130516/67868632/attachment.html>


More information about the Tutor mailing list