git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Print statement


On 2020-01-28 12:14 PM, L A Smit wrote:
> Please help me with this.
> 
> squares =input("\nSquares: ")
> 
> print(float((squares) *float(.15)) *(1.3))
> 
> Cant print answer.
> 
>  ? print(float((squares) * float(.15)) *(1.3))
> TypeError: can't multiply sequence by non-int of type 'float'
> 

You have some superfluous brackets around 'squares' and '1.3', which 
hinder readability.

Remove them and you get -

     float(squares * float(.15)) * 1.3

Now you can see that you have the brackets in the wrong place - you are 
trying to multiply 'squares', which at this stage is still a string, by 
float(.15).

You can multiply a string by an integer, but not by a float -

 >>> 'abc' * 3
'abcabcabc'
 >>>

 >>> 'abc' * 1.5
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
 >>>

You probably meant
     float(squares) * float(.15)

or more simply
     float(squares) * .15

HTH

Frank Millman