Check Yourself


#1

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

```python

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
else:
print “You didn’t type anything!”

<do not remove the three backticks above>

#2

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


#3

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


#4

A basic way is simple concatenation.
Example:

print "You typed: " + original

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


#5

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.


#6

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


#7

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

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

#8

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


#9

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

#10

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