Why should I Check Myself?


#1



I feel like I am missing something. (And if you can't see the colon, it's there, it doesn't work)

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


Oops, try again. Oops! Did you accidentally delete the variable called original?
File "python", line 7
if: len(original) > 0:
^
SyntaxError: invalid syntax

I hoped it would work, but it didn't.


print 'Welcome to the Pig Latin Translator!'

# Start coding here!
raw_input("Enter a word:")
original = raw_input('Enter a word:')

if: len(original) > 0:
    print original
else:
    print "empty"


#2

By the way, the variable "Original" is there, but it says it doesn't. :sweat: :cold_sweat:
EDIT:
Whams head agenst desk. :slight_smile:


#3

Part of your code is redundant and does nothing, I would recheck it.

A hint is that your using a function that returns a value but you are not capturing that data at least one time in your code.


#4

I don't get it. Check what?
(No offence)
I am only 10.


#5

raw_input() is a function so when used returns some data. You have used it one time and it does not capture the data at all.

When you use a function if you need the data ensure that you place the data into a container such as a variable.

var = raw_input("")

Doing this will ensure that you can use the data later.

After that double check your code to ensure you followed the syntax of the language.

EDIT:

Ensure you read your error message. That is a critical point.


#6

Hi,

I had a similar error and I got somewhat believable answer.

another thing I noticed in your code is, semicolon (:slight_smile: at if statement should come at the very end,
here is my code:
`

Start coding here!

original = raw_input ("Enter a word:")

if len(original) > 0:
print (original)
else:
print "empty"
`

hope it helps you ..


#7

Didn't work. Sorry. :sob:
Have a look.
print 'Welcome to the Pig Latin Translator!'

Start coding here!

original = raw_input ("Enter a word:")
raw_input (original)
if len(original) > 0:
print (original)
else:
print "empty"


#8

There is still redundant code in there that is just floating around doing nothing productive.

Example Code:

original = raw_input("Enter a word: ")
if original:  # An empty string is equal to false in python, as such no need to check length
    print(original)
else:
    print("empty")

That is the meat and bones of what you need to do right there.

Break down your problem and create simple instructions you can give the computer.

Example:
1. Get a word from the user, assign this word to a variable for later use.
2. Check if a word was input
3. Print a value based on if a word was entered or not

As you can see I followed this list of instructions I wrote for myself and it worked out great.

If you need any additional information or help feel free to ask.


#9

THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It's perfect!!!!!!!!!!!!!!!! :relaxed::relaxed::relaxed::blush::stuck_out_tongue_winking_eye:


#10

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