I am in a class teaching python and am a beginner at any sort of coding. I keep running into this problem and I can't find anything in my text book or additional handouts explaining what I'm doing wrong. Here is an example taken from one of the exercises that I am having trouble with. The task is to write a program that takes a sentence given by the user and rearrange the words to get "yoda speak". This is what I have.
def main():
print("Enter a sentence and have it translated into Yoda speak!")
sentence= eval(input("Enter your sentence: "))
word_list=sentence.split()
yoda_words= word_list[2:]+word_list[0:2]
yoda_says= yoda_words.join()
print("Yoda says: ", yoda_says)
main()
However why I try to run the program I get this:
Enter a sentence and have it translated into Yoda speak!
Enter your sentence: Jane ran fast
Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.0\src\debug\tserver_sandbox.py", line 14, in File "C:\Program Files (x86)\Wing IDE 101 4.0\src\debug\tserver_sandbox.py", line 5, in main File "", line 1, in ? Syntax Error: Jane ran fast: , line 18
I think the problem comes from me using the whole eval(input()) command wrong. Could someone please explain what I am doing wrong?