10.Ending Up


#1

This is my code:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = [0:len(new_word)]
print original
else:
print 'empty'
It has an error on line 8 and I don't know how to fix it. Here is the error:
File "python", line 8
new_word = [0:len(new_word)]
^
SyntaxError: invalid syntax


#2

Hi this part

new_word = [0:len(new_word)]

Instead of [0:len(new_word)]you should put word[1:len(new_word)]


#3

Additionally, the value to be sliced needs to be specified, this isn't a value:

[1:4]

Python won't understand, it's invalid syntax.


#4

I did what you said to do but it still has an error.
here is the modified code:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = word[1:len(new_word)]
print original
else:
print 'empty'
Here is the error:
Traceback (most recent call last):
File "python", line 8, in
NameError: name 'new_word' is not defined


#6

If the slice is supposed to be all but the first letter of word, then the length of new_word is irrelevant. If it "works" anyway then that's by coincidence and is essentially throwing random words in! That won't do, we need to be more deliberate than that. Every single character in the code should have purpose and be deliberate. If some part of the code doesn't fit that description then remove it and/or learn more about it.


#7

I still don't really get it...


#8

This was my final, which produced the right "pig Latin" word in the editor. It involved changing line 10 to "print new_word" instead of the "print original: from before. Maybe you can do a line-by-line comparison?


#9

Thanks! it was really helpful :smiley:


#10

Attached the screen shot of code.


#11

I have a problem.

It tells me that there is a SyntaxError:Invalid syntax on the 'else:' part of the code.
I can't see anything wrong with it. Can anyone help???


#12

Hi can you post your code?

Here how to format the code


#13

quick question. why do we have to write all of this and create these new functions with in the if statement??


#14

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 = new_word[1:len(new_word)]
print new_word

else:
print 'empty'
print original

Here you are wizmarco
It says there is a Syntax error with 'else:' I don't know what is wrong. @wizmarco


#15

Hi you should indent the print "original" inside the else statement like the print "empty".


#16

since u r really gd in this i just want to show u my code n cn u just tell me whts wrong with it plz


#17

Hi you shoudl indent your code inside the if statement should be like that

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

#18

i did but it still dsnt work sorry


cn u just check if its right coz i m a stupid


#19

try to post your code

here how to format your code


#20

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
print original
word = original.lower()
first = word[0]
newword = word+ first+pyg
newword = newword[1:len(newword)]
print new_word
else:
print 'empty'
is this ok?? idk :slight_smile:


#21

when i said you to indent your code it should be like that.

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0]
    newword = word+ first+pyg
    newword = newword[1:len(newword)]
    print new_word
else:
    print 'empty'