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