Afternoon everyone, I'm having some problems trying to seperate an inputted word within a string into odd and even categories. The problem is supposed to return two output values with the odd and even letters allocated to those respective branches.
Now I have run some trials in which the string was hard coded into the wordStr, and the rest of the process seems to run smoothly under that. So i'm feeling that I'd have to appended something different in order to the program to register the user input. Here's what the code looks like:
def oddEvenWord():
#Objective: program will print out the seperate characters included within a string under where they fall placement wise, odd or even
wordstr = eval(input("Please enter a word to be broken apart into odd and even characters:"))
even_letters = ""
odd_letters = ""
lword = len(word)
index = 0
for index in range(0,len(word)):
if int(index) % 2 == 0:
even_letters += word[index]
else:
odd_letters += word[index]
print(list(even_letters), end = ' ')
print(list(odd_letters), end = ' ')
oddEvenWord()
Like I mentioned above, the program should be able to distinguish between and seperate the odd characters from the even characters in a user inputted word, but the module fails to recognize it as a valid string, as well as invalidating the callback. I'd appreciate it if anyone could give me some pointers in this department