How can I know if my translator works properly?

Question

How can I know if my translator works properly?

Answer

We know from the exercises that led to this point how our program should behave, so let’s check for some key aspects:
When pressing Run, I’m prompted for a word
If I enter nothing, it tells me it’s empty
If I enter something that isn’t strictly alphabetical, it tells me it’s empty (we can change this message to be “invalid” or something more descriptive).
If I enter a strictly alphabetical string, it returns the lowercase version with the first letter at the end of the normal word, followed by ‘ay’.

5 Likes

2 posts were split to a new topic: Why do I Get ythonpa Instead of ythonpay When I Enter Python?

2 posts were split to a new topic: Why is my Translator Not Changing the Input?

My code returns empty regardless of what I type, even though I asked for the correct answer.

4 Likes

spaces are not considered alpha numeric characters, so ensure there are no leading or trailing spaces. If problem persist, please post a screenshot

1 Like

How would one be able to add a space while also keeping the alpha numeric character restriction?

that makes it a lot more difficult, i would argue that then regular expression is fast and the best to use.

or you would have to implement a loop, and and check if the character isalpha or space (' ')

Hey ! … fixed my coding …
just add
out_word = new_word[1:len(new_word)]
print out_word

this will print your typed word as 'Pig Latin translator ’

Sir, fix that bug !!
Thanks and Enjoy coding !

5 Likes

the exercise assumes the correct translation is stored in variable named new_word.

you should replace out_word with new_word. Its exercise specifications, so not much to fix

but, you should store in new variable new_word is already a variable so, use any variable of your choice instead of out_word…

We can reassign variable. Creating yet another variable is not needed here, that will take only extra memory and leave a string in memory we no longer need.

yup!! but be aware of any error …

Mine is not returning the alphabetical string with the lowwecase version and the first letter at the end followed by ay, is there any place where we can see the code well written? Thanks!

exercises have a get solution button (which appears after several failed attempts). But i am not really a fan of that button, you can also make a topic/post with:

your code
exercise url
error message

then we can check your code and help you understand the problem, which will teach you more then looking at the solution.

The exercise is https://www.codecademy.com/courses/learn-python/lessons/pyglatin/exercises/testing-testing-is-this-thing-on-?action=resume_content_item

And this is my code, Could you help me with why it isn´t working? Thanks a lot

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)]
else:
print ‘empty’

the translation is done properly, you only forgot to print it

1 Like

It should print right no?

no, original contains the original input by the user, not the translated/pyglatin version.

Do you really want to print the translation there? The code also gets there when user gives invalid input

can we use [1:len(original)] instead of [1:len(new_word)]as i found it provides best results

no, because then we chop of first and pyg again, undoing some of your own work