It works... not


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/0/1?curriculum_id=4f89dab3d788890003000096#


The code works until I put the else and final print 'Empty.'.

The error message reads like this:
File "python", line 9
else:
^
SyntaxError: invalid syntax


It should either print new.lower or if empty the exact word for it. Empty.


pyg = "ay"
answer = raw_input('Type a word in English:')
word = answer.lower()
first = word[0]
new = word[1:] + first + pyg

if len(answer) >= 1 and answer.isalpha():
    print new.lower()
else:
    print "Empty"

Any ideas?

Edit: Code seems to work now.


#2

Take a closer look at he error message. What is it saying?


#3

When I change the unexpected indent (else has then the same indent as print new.lower, and the print (last line) has the same as else before. But then it says:


#4

If you have corrected the first errorr,

check this part too make sure you have the correct syntax

You wrote

is answer an integer?


#5

No answer is a variable. So...? How do check if there's at least one letter?


#6

Answer is a string. How do you check the length of string? Also you are Missing parentheses on your .lower() call


#7

Parentheses added. Thanks.
I have added len(answer) >= 1 and answer.isalpha(): instead of what I had before.

But error message is.

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


#8

Can you update your original code snippet


#9

Sure, it's done. Wasn't aware of editing possibilities after hours. Sorry.


#10

The else block is still not indented correctly. It has to be inline with the if block.
You can check how to write if/else blocks in python


#11

Code is updated. Seems to work. Thanks for your help!


#12

Mark this thread as solved


#13

Meaning? Selecting an answer as a solution? (Can't find anything else) You helped me out with more than one reply.


#14

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