Check Yourself


Why won’t it print the input I entered?
print “You typed:” original


print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input(“Enter a word:”)
raw_input(“Enter a word:”)
if len(original) > 0:
print “You typed:” original
print “You didn’t type anything!”

<do not remove the three backticks above>


We are just asked to print original. Anyways, printing like this is invalid syntax.


But how would I add “You typed:” in front of the original variable? Just for future reference.


A basic way is simple concatenation.

print "You typed: " + original

Also, check out what @mtf said. :slight_smile:


If you have covered the Strings and Console output module you will be familiar with template formatting…

print "You typed: %s" % original

Although not supported in the old tracks, Python 3 introduced a new format() method that is much more robust.

print "You typed: {:s}".format(original)

but don’t try it in the old track. It will not work without a polyfill.


How would I make it only look for .isalpha() in the input only and not the input + "You typed: "


By keeping original as only user input. Don’t add any other text to it.

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


Yeah but it just spits out what i inputted with no explanation in front of it and it looks bland. I was just wondering for future reference not to pass the exercise


The key is to validate the user input, then you can output it however you like.

original = ...
print "You typed: %s" % original

if len(original) > 0 and original.isalpha():
    print "%s is valid input." % original


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