FAQ: PygLatin - Word Up

This community-built FAQ covers the “Word Up” exercise from the lesson “PygLatin”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Python

FAQs on the exercise Word Up

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why is it necessary that I define the variables word and first inside the if statement?

3 Likes

Because its a logic flow, only when the input is valid it make sense to start forming the pyglatin translation.

furthermore, if the user wouldn’t enter anything (so you get an an empty string), and you try to access by index (for first), you would get an IndexError

4 Likes

My code is passable by the guidlines of the exercise, but it doesn’t produce the desired effect of making the the first letter of the word a lower case one.

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  print original
else:
  print 'empty'

For instance; I type in the word “TEST” and it gets printed in all caps.

1 Like

the conversion to lowercase is successful, but the result of this conversion is never printed

i think that is in a later exercise, but feel free to add this print statement already

1 Like

How about, print(word).?

The lowercase conversion worked on the next part of the exercise. I went back to this problem and after a page refresh it work just fine.

Thanks

1 Like

what’s the point of creating

new variable called first that holds word[0] , the first letter of word.

instead of getting it straight from variable original?

  original = original.lower() 
  first = original[0]
1 Like

There’s always a question of when to use intermediate variables and when to bypass them. Sometimes using them adds clarity, sometimes it just makes your code unnecessarily verbose.

After all, you could do the whole thing with no intermediate variables at all:

print(original.lower()[1:len(original)] + original.lower()[0] + 'ay')

Would you recommend that for a beginning class?

3 Likes

Hey Patrick! Thank you for your swift answer and clarifying that some pieces serve solely readability! :smiley:

2 Likes

I wrote the same code as given in answer. Why does it not accept my answer correct? From last two steps I am forced to view solution. When I check the solution, it is the same what I write.

Can we see the code that didn’t pass? Do you still have it?

Once I ran my code, I’m asked to “Enter a word” in the interpreter box, what should I type in there?

Whatever you want. Its an opportunity for you to test your program.

I’ve completed the instructions given for this exercise but it is still asking me to “create a variable called word”, even though I already have, every time I type into the console to test my program. Does anyone have an idea why this happens?

Without seeing the code you wrote, no. Sometimes raw_input causes hangs in the browser, you can try refreshing etc. to clear it up. If that doesn’t work you can submit the issue to the forum but if submitting code please try to format it with backquotes/accent grave-
for example…
` ` `
x = 3
` ` `
becomes

x = 3

More formatting info-

code

This is the piece of code that I wrote for the exercise. It looks correct to me but it still gives me the same error message as before. I tried to refresh the page but it did not change anything. What did I do wrong?

1 Like

Please try to format code before submitting it the forums. Screenshots are better than nothing but not as easy to check.

I tried this on my own interpreter and it ran fine. Went through the lessons online up to this point and then weirdly got stuck at the exact same point as you did :laughing: Kept getting code that got stuck at the prompt and a hint that ‘word’ was not defined. A couple of print statements suggests the hang acutally occurred immediately after raw_input was used.

Resetting the lesson didn’t work, neither did using the solution. I had to clear our my browsers cache in order to get through the lesson. Somehow the old instances weren’t getting cleaned up and somewhere, somehow raw_input was never dealt with. I’d look into clearing out your browsers cache unless anyone else has a bright idea to kill off old instances (which I what I assume is happening; reminds me of helping out in a class on C when students had to use scanf and you pop over to help and they have nigh on a hundred prgorams running at once).

1 Like

Huh, that’s pretty weird. I’ll try and clear my browser cache to see if it gets up and running again, thank you so much for trying this hard to get it to work, it’s pretty awesome of you!

2 Likes

I’m using this code and it tells me ‘Traceback (most recent call last):
File “python”, line 3, in
ExecTimeoutException: Program took too long to terminate.’

This is the code.

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
else:
    print 'empty'