How can I know if my translator works properly?


#1

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’.


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

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


#7

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


#8

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


#9

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


#10

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


#11

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 (' ')


#12

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 !


#13

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


#14

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


#15

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.


#16

yup!! but be aware of any error …


#17

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!


#18

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.


#19

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’


#20

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


#21

It should print right no?


#22

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