Need help (what did I wrong?)


#1

pyg = "ay"
original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()
first= "word"[0]
new_word = word + first + pyg
new_word = [1:len(new_word)]

print original

else:
print 'empty'

File "python", line 9
new_word = [1:len(new_word)]
^
SyntaxError: invalid syntax


#2

This is because you need to equal new_word to the slice and the what?

Also your "word"[0] will bring up an error later on because of the quotes. Get rid of them.


#3

now it is

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()

new_word = word + first + pyg
new_word = word[1:]

print original

else:
print 'empty'

ops, try again. It looks like new_word contains "ord" instead of "ordway"!

Hm I dont know what to do ...


#4

Ok I meant for that statement just get rid of the quotes you actually need that part of your code haha. Sorry about that.

Secondly, think about new_word = statement. Your getting their. First off, you need to equal new_word to your slice or else your pig latin translation will be off. But secondly, new_word can't just be the slice of the word is has to be the new word we just got plus the slice. We can't slice the old word we have to slice the new word!


#5

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()
first= "word"[0]
new_word = word + first + pyg
new_word = word[1:len(new_word)]

print original

else:
print 'empty'

so I add it on and change it to [1:len(new_word)] but it is still not working

sorry for any inconvenience Im plainly stupid :confused:


#6

You are so close honest! Don't call yourself stupid we all have to learn somehow. I bang into a brick wall several times before I use the door :stuck_out_tongue: Anyhow, lets look at the above part. Notice that I stressed new word needs to be equaled to new_word along with the slice not the old word.

Also, this won't throw an error, but again, the point of this code is to get a new word print the new_word that you got onto the screen and not the first one so you can see what your translator came up with! :smiley:


#7

word = word[1:len(new_word)]


#8

but i get wordway instead


#9

Ok I may not have been clear enough. You have new word in your slice but thats not the new word im talking about. You see you are given the slice: [1:len(new_word)]. But you need slice plus newword_ to equal the new_word or else the final translation of the word will come out wrong.


#10

Ah Alright ! Thank you


#11

No problem! Glad to be of service! :smiley:


#12

The second line eliminates the work of the first line here.


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.