Suggestion: print new_word at the end


#1



At the start of the Pig Latin exercise, we are asked to print the original input string if the input is not empty and is made up of alpha characters.

python
if len(original) > 0 and original.isalpha(): print original

This is likely done so to provide a simple example of writing an 'if' statement in a program.

By the end of the exercise, this segment of the code is left untouched, ie. we are still printing out the original input instead of the altered input. It feels like there should be some indication that we ought to change the printed statement, ie to

python
if len(original) > 0 and original.isalpha(): print new_word


#2

The thing is, you can't. It will throw an error since you've never defined what new_word is.
You can print new_word when you have defined it beforehand.


#3

I just did this and found it odd aswell. After reading your reply i went back and checked my code.

During the exercise new_word was defined and when i changed the if statement to print new_word instead of original at the end of the exercise there was no error...it printed the new pig latin translation as you would want it to.

Might be something to change so its actually a translator.


#4

Oh you're talking about the whole section. Got it. Got confused about which parts of the exercise you were referring to.

Yeah they should tell you when to remove print original. I just got rid of it on my own at some point where I find that it wasn't needed. The section does tell you to add print new_word but not change original to new_word.

I just find it odd to have your print new_word before your definition of it: new_word = word + first + pyg but yes, it won't throw errors.


#5

Yeah, I mean at the end of the entire section. Of course, it is a minor thing and I'm sure that many people would have changed 'print original' to 'print new_word' at some point, but it seems like something that should be explicitly stated since this is one of the first few complete programs we write.


#6

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