FAQ: Learn Python - Pyglatin - Testing, Testing, is This Thing On?

If you’re learning anything at all, it is that there are workarounds. Put that learning to use.

Trying to add into the translator. I have done the below so far to allow the ability to escape if someone types in wrong input. What I would like to happen is if the input is wrong to be prompted again for a word and if wrong 3 times then ask if they want to quit. I was thinking a loop but I started with the below and it feels clunky and I want to implement this correctly. I know that a function could do this but memory limits etc… Thanks in advance for the help.

pyg = 'ay'
original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  new_word = word + first + pyg
  new_word = new_word[1:len(new_word)]
  print new_word
else:
  print 'No Numbers or Spaces.. only letters'
while True:
    cmd = raw_input('Do you want to quit? Enter \'q\'!')
    if cmd == 'q':
        break

I keep getting: Traceback (most recent call last):
File “python”, line 3, in
ExecTimeoutException: Program took too long to terminate.

After you click Run, be sure to click the prompt in the console. Then type a word and Enter. If that doesn’t work, then comment out the input statement and assign a literal value so you can run the program to a final result. That will get you through the exercise.

This is my code:
pyg = ‘ay’

original = raw_input(‘Enter a word:’)

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

word = original.lower()

first = word[0]

new_word = word + first + pyg

new_word = new_word[1:len(new_word)]

print new_word

else:

print 'empty'

When I type anything, why does it return ‘empty’?

Comment out that line and just hard code a word.

original = "surprise"

Then you can see the code run and pass the lesson.

I had to put show solution to every exercise because it wouldn’t let me move forward. Where do I type the word to enter into the translator?

worked very well for me!!! THANKS!! do you know why theres a difference between the space between : and 'tho?

It’s simply for visual effect. Without it, there wouldn’t be a space between the colon and the user’s input in the console.

Without Space

Enter a word:hello

With Space

Enter a word: hello

Thanks for the reply. However, I think there’s more than that as there’s a difference in the output.

When I type

original = raw_input (‘Enter a word:’)
vs
original = raw_input ('Enter a word : ')

the first one prints empty no matter what’s my input.

What do you mean by “prints empty”?

print ("Empty")

according to the instructions, as I recall.

1 Like

my bad, I tried to say it prints nothing at all for the first input. my code now, but my question was similar to sliosi, and was solved by the space issue suggested by design7184503999 - wanted to know why did the space change the output… it somehow works now; sorry if i caused any confusion :sweat_smile:

1 Like

raw_input seems not working for this lesson.
I am using the solution or replacing raw_input with string to proceed.

image
I need help, my code is the same as the solution, but it keeps saying that there is an error on line three?

Suggest read through this topic and note some of the suggestions and workarounds.