How can I know if my translator works properly?

Can u plzz explain how does line work

here:

https://www.pythoncentral.io/cutting-and-slicing-strings-in-python/

scroll down to the slicing bit.

you slice the first letter of the string, as part of the translation to pyglatin

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

Except it doesn’t. I’ve gotten tot he last section of the lesson, it’s passed me, and when I type in a word it returns that word exactly as I typed it with no amendments, lowercase, translated, or otherwise. I don’t understand how this is happening if I’ve been passed on the previous parts of the lesson.

Never mind I worked it out - the original Print Original has to be changed to Print new-word. It doesn’t say to do this in any of the instructions. I get that I’m on the free version so it has limited help but this is negligence, I would pay for membership if the cost wasn’t extortionate…

Hi,
when I try testing my code with strings having large number of characters say some 20, 26 etc some of the characters are getting cropped. Please see the screenshot for one sample and let me know it is expected.

1 Like

Really confused by this lesson. The code seems to work (in a way), however it’s only translating the word I input BEFORE the word I currently input. Example: if i type in Ear it doesn’t do anything, but then if i type in Dog, it then will display: areay (the translation for the previous word ‘ear’.

Here is my code. Hopefully someone can explain to me what is happening because even the solution code they provide doesn’t seem to differ from mine.

Thank you!

pyg = ‘ay’

original = raw_input(‘Enter a word:’)

if len(original) > 0 and original.isalpha():
print new_word
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
else:
print ‘empty’

sounds like a glitch, what if you run the code on repl.it?

1 Like

Went to that site. It’s throwing all kinds of errors on things that work fine in the codecademy

Did you pick the right python version? And if you want help, please be a bit more descriptive. You could share the repl with your code

It looks to me like you’re printing ‘new_word’ before you defined it and gave it a value, in your fourth line of code. The new_word variable is given something to store from raw_input only after you tried to print it earlier. I’m guessing the first time you run it, it prints nothing. The second time you run your code, it does not find a new value for new_word, and therefore immediately prints the value that you had most recently/previously stored as new_word.

Hi everyone, I have a question as below:
Assume I enter the word “victory”, the position of the characters in the word is as below:

v  i  c  t  o  r  y
0  1  2  3  4  5  6

If I use len(word), the result would be 7

If I want to output the final character of word, the command should be:
print word[len(word) -1]

So why if I want to output from character at position 1 to the final position of the word, I have to use the command:
print word[1:len(word)]

I think, print word[1:len(word)-1] must be the corrected one but actually it’s not

Could any one give me the explanation for the difference?

string slicing has the following general syntax:

"some string"[start:stop]

however, the stop value itself is not included. Its lesser then (<) the stop value, not lesser then or equal to (<=)

this differs from accessing string by index, which has to do a lookup at that index, so then you actually need length - 1 for the last value.

1 Like

Thank you for the explanation. I can understand it clearly now. :smiley:

When I enter a word like ‘Fight’ this give me an output as 'fightfay. But according to the instructions regarding the working of Pyglatin it should print ‘ightfay’ , What should I do ?

pyg = 'ay'

original = raw_input('Enter a word:')

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

seems you string slicing isn’t working properly, but difficult to say why without seeing the code

What is happening here? above says variable right, but then when i run save i get this in both Firefox and Opera. I have Python 3.7 installed on my computer with Anaconda

traceback (most recent call last):
File “script.py”, line 4, in
calorie_stats = np.genfromtxt(‘cereal.cvs’, delimiter= ‘,’)
File “/usr/local/lib/python2.7/dist-packages/numpy/lib/npyio.py”, line 1549, in genfromtxt
fhd = iter(np.lib._datasource.open(fname, ‘rbU’))
File “/usr/local/lib/python2.7/dist-packages/numpy/lib/_datasource.py”, line 151, in open
return ds.open(path, mode)
File “/usr/local/lib/python2.7/dist-packages/numpy/lib/_datasource.py”, line 501, in open
raise IOError("%s not found." % path)
IOError: cereal.cvs not found.

It looks like Python is not able to find file cereal.cvs.

My guess is that you made a typo in the extension because cvs is a drawning format and the file probably has extension csv.

If that does not work you can pass a fully qualified path to the genfromtxt method, this should resolve the problem.

Hi, I think the problem is in line 10:
new_word = new_word[0:len(new_word)]

It should resolve if you change the 0 for a 1.

Also, the last line (print new_word) should be in line 11 (before the else:)

I have the same problem and I completely don’t understand what you mean?

this programs translates user input (stored in original variable) into a pyglatin version (stored in new_word variable), so if you want to see the pyglatin version/translation, you will need to print it