"Testing, testing, is this thing on". How can I make the most of this exercise?


Hi there guys, I recently completed the "Pyglatin" course of Python and it was the one part of Python that confused me the most. I sometimes got the answers but did not really know why or how I actually got the answers. To be honest, I had to use the Q&A a good bit for this portion of Python. When I went to the Testing Testing part of PygLatin (the very last part) which talked about debugging (as someone wanting to break into a career in CS I know I will be doing this a lot), I simply noticed that if you just submitted your code it practically passed you. This is the code I submitted:

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

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = new_word[1:len(new_word)]

How can I toy around with this section of PygLatin more and get more out of the learning? Any suggestions?

Also, how do I add comments?


Review all the concepts, as trivial as they may appear. Each step has a purpose and we should be comfortable with our understanding of the role it plays.

pyg = 'ay'

Defining string constants and initializing other working variables is generally the best first step in a program. We also initialize the main working string in this step, so,

original = raw_input( ... )

is part of the initialization process.

When user inputs are present in the data, it is important that we validate it before proceeding further. We need to be sure we are not feeding illegal values to the program.

if len(orginal) > 0

tests the input for string length. This lets us avoid any empty strings. Cannot really process nothing, ay?


tests that the string contains only letters, also important since even while this is a pseudo-language, it is still not gibberish.

word = original.lower()

preserves the original inputs and mutates the copy which is assigned to word. In practice it is often necessary to preserve inputs, especially if our program is modifying the data. We can do whatever we wish with the copy.

The next steps are the final composition of the new word adapted to the Pyglatin language syntax.

first = word[0]                 # a copy of the first letter

new_word = word + first + pyg   # build the working string

To complete the process we take a slice of the new_word string that excludes the first letter:

new_word = new_word[1:len(new_word)]

The above shows explicitly that we are taking the entire string from the second letter onwards. The implicit slice will return the same...

new_word = new_word[1:]

but it is not as obvious until we are comfortable with the notation.

That's the review portion. Next comes the tinkering and experimentation. Work with the concepts, not the code alone. Stretch your understanding of each one by applying it in as many different test cases as you can dream up.

How many ways can we use length information?

Where else might we have need to test for letterness?

How well do we understand string manipulation and slicing?

And so on...


Thank you! So grateful for this since I did have issues trying to make sense of it all.

One more thing, how do I actually add comments and make them show up in the where I am asked to enter a word. I keep getting "none" right below what I enter, this is the code I have been running so far and it seems like print messes the whole thing up:

pyg = 'ay'
original = raw_input("enter:")

if len(original) < 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = new_word[1:len(new_word)]


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.