10. ending up


#1

Can someone help me please?

I don't know what's the problem here:

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

This is the error shown:

File "python", line 10
else:
^
SyntaxError: invalid syntax


10. Ending Up
#2

else can only be after if or elif, which means this lines:

first = word[0]
new_word = word + first + pyg
new_word [1:len(new_word)]

need to be indented to be inside the if clause


#4

Even though it shoudn't be a porblem, you NEED to only define "new_word" once!
You need to combine your lines so it reads,
first = word[0]
new_word = [1:len(new_word)] + first + pyg

Trust me, this will work. I had the exact same issue :slight_smile:


#5

enjoy :slight_smile:


#7

pyg = 'ay'

original = raw_input('Enter a word:')

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

else:

print 'empty'

I think this is the right answer. It worked :smiley:


#8

I'm a bit baffled as to why you don't put spaces between your = and + but the code works so I'm happy


#9

pyg = 'ay'

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

This code would run


#10

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