#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    "if" Statement problem


    Learning Python, but I have a problem. I'm using Codeacademy.com and while making an English to Pig Latin converter, I came across something I've never learned. It is asking me to "Write an if statement that checks to see if the string is not empty.
    If the string is not empty, print the user's word."

    So far I have

    print "Welcome to the English to Pig Latin translator!"
    original = raw_input("What's you name?")
    if len("original"):
    print
    else:
    print "empty"


    I cannot figure out how to print the users input if the string is not empty. Any ideas?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    Understanding variables causes your trouble. The if statement could be construed as conceptually correct.

    Code:
    print("Welcome to the English to Pig Latin translator!")
    original = raw_input("What's you name?")
    if len(original):  # test the variable, not the constant string "variableName"
        print original
    else:
        print "empty"
    
    
    if original:  # an empty string tests False, you can bypass the len function.
        print original
    else:
        print "empty"
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo