Shaman Posted February 2, 2015 Share Posted February 2, 2015 Alright so currently the website has me slowly creating a Pig Latin translator. Currently the script/code is as follows. pyg = 'ay' original = raw_input('Enter a word:') if len(original) > 0 and original.isalpha(): print original word = original.lower() first = word[0] s = "Hello" print s[1:5] new_word = word[1:len(word)] + first + pyg else: print 'empty' It is stating that I did the exercise correctly but I don't understand how it could be when it is returning the following Enter a word: Hello Hello ello None From what I am seeing the screen should be returning "Ellohay" not just "Ello". I'm rather confused with this as to me it's not correct but the system is telling me it is and to move on. Can anyone shed some light on why it is doing this? Note: I'm probably going to be making this a thread for when I have the odd question lol. Quote Link to comment Share on other sites More sharing options...
Icon Posted February 2, 2015 Share Posted February 2, 2015 (edited) s = "Hello" print s[1:5] i don't get why this is here. I'm assuming it's because you were testing (or were supposed to be testing out) how String arrays work? How [1:5] would take the word from point 1 (E) to point 5 (O). See you are making a "new word", by taking all but the first character, then taking the first character and putting it in the end, then adding pyg (which is "ay"). The code you have does all that, but it never prints. s = "Hello" print s[1:5] new_word = word[1:len(word)] + first + pyg I think it should be pyg = 'ay' original = raw_input('Enter a word:') if len(original) > 0 and original.isalpha(): word = original.lower() first = word[0] new_word = word[1:len(word)] + first + pyg print new_word else: print 'empty' IMO you should go through and comment every line you can and say what it does and what it's purpose in the script as a whole is. Edited February 2, 2015 by Icon315 edited to somewhat put together the wreckage i call a train of thought Quote Link to comment Share on other sites More sharing options...
Shaman Posted February 2, 2015 Author Share Posted February 2, 2015 (edited) s = "Hello" print s[1:5] i don't get why this is here. I'm assuming it's because you were testing (or were supposed to be testing out) how String arrays work? How [1:5] would take the word from point 1 (E) to point 5 (O). See you are making a "new word", by taking all but the first character, then taking the first character and putting it in the end, then adding pyg (which is "ay"). The code you have does all that, but it never prints. s = "Hello" print s[1:5] new_word = word[1:len(word)] + first + pyg I think it should be 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[1:len(word)] + first + pyg print new_word else: print 'empty' IMO you should go through and comment every line you can and say what it does and what it's purpose in the script as a whole is. That was how I originally had it, I changed it back as you can see here. In the previous exercise it had wanted me to create the s[1:5] variable so it would actually print "ellohay". This is supposed to be a pig latin translator but as you can see it is just returning whatever word I type in and claming it is correct. This is what is so confusing to me. So it is actually doing what it is claiming just it's not printing it on screen? Edited February 2, 2015 by Alten Quote Link to comment Share on other sites More sharing options...
Icon Posted February 2, 2015 Share Posted February 2, 2015 In the code you are showing you are not returning "new_word", you're creating it then not doing anything with it. pyg = 'ay' original = raw_input('Enter a word:\n') if len(original) > 0 and original.isalpha(): //Removed the line that prints the original since it's not neccessary word = original.lower() first = word[0] new_word = word[1:len(word)] + first + pyg print new_word // This is the line that gives the output else: print 'empty' Quote Link to comment Share on other sites More sharing options...
Shaman Posted February 2, 2015 Author Share Posted February 2, 2015 Lol I should have realized I needed to add the print function in. I was thinking only about doing exactly what the exercise wanted which it hadn't stated that. Need to pay more attention. Also makes sense as to why it is saying pass when it wasn't printing it out on screen. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.