python - Draw a triangle out of asterisks using for loops -
size = int(input("enter odd number width: ")) row in range(1, (size+1)/2, 1): character in range(1, size): print("*"*character) why keep telling me "float object cannot interpreted integer"? know because of (size+1)/2 don't think should make difference?
its supposed create triangle looks this:
* *** ***** ******* ********* *********** ************* (rows width+1/2, , entered number largest row of asterisks, rows increase increments of 2 each time (i.e. 1, 3, 5, 7, 9, 13).
because (size+1)/2 could theoretically have fractional part, python returns floating point number it. range doesn't accept floats because there no general way turn integer without potentially losing information. neither of these steps special-cases particular inputs don't trigger these problems.
you don't care things, because consider size being invalid input. python doesn't know don't care potential data loss unless tell - can this:
(size + 1) // 2 this removes fractional part of number, , gives integer part (ie, rounded toward minus infinity).
Comments
Post a Comment