What criteria do we need to set to make sure the user entered a valid word ? I'm a going based off of if the input is string but i am not sure how to invoke a string type or return the input variable type. Here is my code below:

word = raw_input("Enter a word in english: ")
if type word == type str():
temp = word[0]
word = "y" + word + temp + "ay"
print word
print "try again"


@redalati: To make sure the user input's type is a string, simply do:

if type(userInput) == str

If the above condition is True, continue, but if it's False, do not continue.
In this exercise, there's no such need for that but it's always a good practice to think about error handling.

If you want to print the input's type, simply use:

print type(userInput)

Hope I was clear and that it helps you!


Thank you for your response!

I tried this as you suggested:

word = raw_input("Enter a word in english: ")
if type(word) == str:
temp = word[0]
word = "y" + word + temp + "ay"
print word
print "try again"

but when I type in "python" as the input for example (without quotes) I get the try again error


@redalati: That's because strings don't have the pop() function, that's for lists.
Strings are immutable so trying to alter a value at a giving position of your string, won't work.
In order to "remove" something from a string, you should use string slicing.


But then why do I receive a "try again" when the first condition type(word) == str: is true? Shouldn't I receive an error if word.pop() runs?

Thank you!


@redalati: I believe it doesn't even get to print anything from it since raw_input will return a string containing the input of the user, not a list.
Here's the proof:


Hmm this is what my output looked like:


@redalati: Check the instructions, please.
Look what they're telling you to print.


Oops sorry it went to the subsequent lesson by default (which builds on the same code) . Here is what I meant to show:

The lesson shows up as complete but it didn't do what it was intended to.