Hey guys, I'm a new student to Python 3, and I'm having some issues with an assignment, so I'd appreciate the help.
What I'm doing in the assignment is taking a user-inputted string, splitting it, and printing it out in a triangle (if it's even, inverted triangle if it's odd, but I have that part working great)
So here's where I have a problem.
So, the string is identified as being eve, and I'm making the attempt to use a string-split to only print half the string at a time.
When this runs, I receive an error that states:
If I NEED to use an integer in my string-split, I don't know how to do it gracefully. The only thing I can think of is to have if statements for each possible even-numbered string.
Thanks for the help guys, I appreciate it!
What I'm doing in the assignment is taking a user-inputted string, splitting it, and printing it out in a triangle (if it's even, inverted triangle if it's odd, but I have that part working great)
So here's where I have a problem.
1 2 3 4 5 |
if len ( myString ) % 2 = = 0 : numA = ( len ( myString ) / 2 ) numB = ( numA + 1 ) halfA = myString [ : ( numA ) ] halfB = myString [ ( numB ) : ] |
When this runs, I receive an error that states:
Error:TypeError: slice indices must be integers or None or have an __index__ method
We haven't learned about any __index__ method, and my text book, as well as online resources, aren't giving me any clues as to what I'm doing wrong.If I NEED to use an integer in my string-split, I don't know how to do it gracefully. The only thing I can think of is to have if statements for each possible even-numbered string.
Thanks for the help guys, I appreciate it!