Welcome to the Treehouse Community
Looking to learn something new?
Francis Neal528 Points
Why // and not just / in the (num_of_char // 2) line?
In the line:
result = text + "!" * (num_of_char // 2)
Why do we need // and not just /? Just / returns the error:
result = text + "!" * (num_of_char / 2)
TypeError: can't multiply sequence by non-int of type 'float'
Steven Parker216,012 Points
The string (sequence) multiplying operation only works with an integer repeat count, but the normal division operator (/) always returns a float result which is not compatible.
Using the integer division operator instead (//) returns an integer result.
You could also use "
int(num_of_char / 2)".
Martin Luckett32,591 Points
(Originally added as comment rather than an answer - oops)
// is the floor division operator which is also sometimes called integer division and returns an integer whereas / may return a float (non-integer).
For example, 5 / 2 will return 2.5 (a float) where 5 // 2 will return 2 (an integer).
Multiplying text requires an integer as, for example, text plus "!" times 2.5 does not make sense.
It is a TypeError because the multiplication of sequences requires integers and using a single / can give a float.