Why is this wrong? I see no reason... Please help


#1



Lesson I'm stuck at:

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

It says that Im doing something wrong... I can't seem to find my mistake... The message says:

File "python", line 6
if original > 0
^
SyntaxError: invalid syntax

I thought that it would let me check to see if the user had entered text into the console... This is my code:


print 'Welcome to the Pig Latin Translator!'

raw_input("Enter a word:")
original = raw_input

if original > 0 
    print original
else:
    print "empty".


#2

Take a closer look at the instructions. You want to see if the length of original is greater than zero. Also,

raw_input("Enter a word:")
original = raw_input

needs to be more like

original = raw_input("Enter a word:")

#3

I will try that, Thank You!!!


#4

@jdlcoder It seems like your code has more problems than one. @zh30 Only listed one of them. You forgot the colon at the end of your if statement. Also, your raw_ input value will not work, as you technically didn't assign it as a value in original. you can either do:

original= raw_input("Enter a word:")
``` 
 Or:

```
raw_input = raw_input("Enter a word:")
original = raw_input

Also, your second problem is this:

Technically by that statement you are checking if the value of original is more than 0(i.e. if original is 2 if 2 > 0). So, if the user inputs words, that won't work. @zh30 was wrong when he said

It is suppose to be zero, but you are suppose to check the length of original is greater than zero so that you know the user has not given you an empty string. Your actual if statement is suppose to be like this:

if len(original) > 0:

If you fix all those, then you should be good. Ultimately, your code should be good if you followed all the instructions. if you still need help let me know.

Good luck! Hope that works for you and happy coding! :slight_smile:

-- @chipjumper36731


#5

Thank you! I will fix this...


#6

pyg = 'ay'

word = original.lower() 
first = word[0]

original = raw_input('Enter a word:')

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

This is my code. It doesn't work. I read the instructions. I don't know why it doesn't work. Sorry, I know Im bad at python, I just need some help. Thanks, JDLCoder


#7

This is the lesson: https://www.codecademy.com/en/courses/python-beginner-2W5v7/1/2?curriculum_id=4f89dab3d788890003000096#

This is the error:

File "python", line 8
if len(original) > 0 and original.isalpha() word = original.lower() first = word[0]:
^
SyntaxError: invalid syntax


#8

That's exactly what I said, check the length of the variable original to ensure it is greater than zero.


#9

Sorry my bad. I misunderstood. :slight_smile:


#10

Hey @jdlcoder! It is totally okay to be wrong sometimes!

It doesn't mean you are bad at it! :smiley:

The 'first' and 'word' variable sequence should be under the if statement. Also:

You seem to over complicate the if statement. All you need to check in there is if the user's string is blank and make sure it isn't containing numbers. So, the first part is right, but the part from word is what is messing you up. Ultimately, your code should look like this:

pyg = 'ay'

original = raw_input('Enter a word:')

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

That should do it for you. Let me know if you don't still understand or need more help with the code. Good luck and happy coding! :slight_smile:

-- @chipjumper36731


#11

Thank you so much! You're a huge help!
I will let u know if Im stuck again (probably soon :smile: )


#12

@jdlcoder No problem, Glad to help! And you can ask for help anytime. :slight_smile:


#13

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