+ 2
Why does this calculation not work?
3 Respostas
+ 2
Calculators are used for math instead of language/words.
You don't have a list, you're using an array. If you're specifying the indices of them, then you'll use string[index] for arrays and list.index() for items of a list. Indices need to be int. Not to mention that you don't subtract numbers from words; that's not math.
What exactly is your goal in the code? I'm more than happy to help you out with it.
+ 2
After reading your code more, I -think- you're trying to remove the letter at the particular index right? Basically, take the length of the string, divide it in half, and remove the letter that's at that index?
This may be helpful, replace your print statement at bottom with this:
print(a.replace(a[int(i)], ""))
^That's going to look at the string, grab the index your want and then remove the letter in that dex. In your example, the output would be "wod"
+ 2
inputs = []
i = input()
x = i.lower()
t = len(x)
def length():
if len(x) % 2 == 0:
print("The word is '" + str(x) + "'.")
print(x.replace(x[int(i)], ""))
else:
print("The word is invalid, please enter an even lengthed word.")
length()
#Why does this not work like you told me?