1

i am trying to learn python by myself on codeacademy, and i am looking through past lessons, but i can't figure out what i did wrong. i think i copied everything correctly.

the assignment is to check the user input word to see if it contains at least one character. if it does contain more than one character, the program is supposed to print the word the user inputted in the beginning. if not, the program is supposed to say " empty".

the code lets me input a word, but then even if the word has more than one character, it will not print out the word. i feel like the solution is probably very simple, but i can't figure it out. i think the semicolons are in the right spaces. i would appreciate your help very much

print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")
def true_function():
    if len(original)>= 1:
        print(original)
    else:
        print("empty")
3
  • You should use input() in Python 3. Commented Jul 8, 2013 at 6:17
  • @squiguy It's not python 3 (Codecademy teaches 2.7) Commented Jul 8, 2013 at 6:34
  • @Haidro I saw print(). I guess I should read more :). Commented Jul 8, 2013 at 6:35

4 Answers 4

5

It's because you never call the true_function() function.

You can either remove that, and just have:

print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")

if len(original)>= 1:
  print(original)
else:
  print("empty")

Or, call the true_function() afterwards, passing the variable original as an argument:

def true_function(original):
  if len(original)>= 1:
    print(original)
  else:
    print("empty")

print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")
true_function(original)
Sign up to request clarification or add additional context in comments.

Comments

1

you need to call the true_function() for it to be executed

do something like this

print "Welcome to the English to Pig Latin translator!"

def true_function():
    original = raw_input("tell me your secrets")
    if len(original)>= 1:
        print(original)
    else:
        print("empty")
true_function()

notice how i call true_function() before you were just taking input and thats it but know the input is asked in the function then ran through the condition

here are a few tutorials on functions if you dont fully understand

Tutorials point: Functions

ZetCode calling functions

2 Comments

oh wow, the solution is so simple and it works now :D I saw yours first, so i'll accept it when the time counts down. Thank you very much !
no problem i used code academy when i learned to keep it up :)
0
original = raw_input(...)

That returns user input to a variable called output.

def true_function():

this like defines a function. note that it doesnt really do anything, more like just tell python that something like true_function() exists.

now if you call true_function() your code will work. But i would suggest the following changes.

def true_function(arg):
    if len(arg)>= 1:
        print(arg)
    else:
        print("empty")

now note, that your function takes an argument called arg. whenever you call this function, you give it a variable in the function call like

true_function(original)

see python function documentation for more details

Comments

0

Mate you need to call the function . Also the function should take string argument ,as I am assuming you will be enetering string as the input.

def true_function(string):
    if len(original)>= 1:
        print(original)
    else:
        print("empty")

print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")
true_function(original)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.