I dont know how to give has_chars an argument. can someone help me check it


#1

print 'Welcome to the Pig Latin Translator!'

Start coding here!

raw_input("Enter a word:")
original = raw_input
empty_string=" "
def has_chars():
if len(empty_string) > 0:
print original
else:
print "empty"
if has_chars(original) and the_string.isalpha():
print original
else:
print "empty"


#2

Hi @smart_aleck,

You don't need the has_chars function. Simply check whether the len of original exceeds 0. Also note that the_string is undefined. Accordingly, this ...

if has_chars(original) and the_string.isalpha():

... should be ...

if len(original) > 0 and original.isalpha():

However, if you have created the has_chars function for the purpose of practicing writing functions, and wish to pursue that purpose, you could do this to call the function ...

if has_chars(original) and original.isalpha():

However, now you must get the function to work properly. Provide it with a parameter, then test the len of that parameter inside the function. Instead of printing the result, return either True or False, as follows ...

def has_chars(word):
    if len(word) > 0:
        return True
    else:
        return False

That could be simplified to ...

def has_chars(word):
    return len(word) > 0

You could instead write a function that does all the checking ...

def is_valid(word):
    return len(word) > 0 and word.isalpha()

Also note that an advisable way to use the raw_input function is to call it and assign the result to a variable. You can do that in one line, as follows ...

original = raw_input("Enter a word: ")

#3

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