Received error, yet passed?


#1



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


File "python", line 13
if len(original) > 0
^
SyntaxError: invalid syntax

Was the error I was given, but it told me I completed the exercise. Also, I don't understand why the syntax is incorrect.


I expected for me to fail, but for whatever reason it passed me. Is this normal?


"""
This will ask for a word, and set up the variables required for translation.
Line 12: Asks for a word.
Line 13: Confirms there is a word.
Line 14: Sets the variable for addition to the end of the word.
Line 15: Sets the variable for the first letter to be moved to the end.
Line 16: Sets the variable for the letters after the first one. 
Line 17: Conversion to piglatin. 
Line 18: Prints translated word.
Line 19-20: Prints line to let us know word was invalid.
"""
original = raw.input("Please input a word for translation")
if len(original) > 0
    pyg = "ay"
    first = original [0]
    second = < original [0]
    new_word = %s + %s + %s / (second, first, pyg)
    print new_word
else:
    print "No word was found"


#2

raw_input() its a function, with a underscore in the name, not full stop


#3

.< Oops! I fixed that part. I've been looking at other peoples code to see if I was missing some stuff, and adding "and original.isalpha()" to the end of the IF line fixed that original issue.

There's now an issue in the line with variable second. I'm trying to have it pull the letters after the first letter of the word and make that a variable called second, I realized that I put less than in this code, I corrected that as well. The issue still remains. So now my code minus comments looks like this

original = raw_input("Please input a word for translation")
if len(original) > 0 and original.isalpha():
    pyg = "ay"
    first = original [0]
    second = > original [0]
    new_word = %s + %s + %s / (second, first, pyg)
    print new_word
else:
    print "No word was found"

And the error is now

  File "python", line 16
    second = > original [0]
             ^
SyntaxError: invalid syntax

Am I along the right track at least? I'm trying not to look at other peoples code, I figured that's cheating myself. I don't quite understand how this is incorrect.


#4

what are you doing here? And what are you trying to achieve?


#5

What I was trying to do was make a variable for the letters past the character in slot [0], so anything past the first letter so I can pull just that later on when needed. Am I just overthinking this?


#6

to achieve this, use string slicing:

string[start:stop]

#8

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