Translator stuck on one previous input!


#1

I have come to finishing and tidying up my code:

pyg = ‘ay’
#‘pyg’ is the suffix added to the end of the word

orignal = raw_input('Enter a word: ')
#‘original’ is exaclty what the user enters before we modify it
if len(original) > 0 and original.isalpha():
#This line ensures that the entered word contains no numbers and is not empty
word = original.lower()
#This just tidies up the cases in the inputed word
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
#This removes the first letter
print new_word
else:
print ‘empty’

However I discovered that it will keep translating a word I previously inputed (Joshypoo) ignoring whatever I type into it. Having used print the problem seems to be that the raw_input never changes despite what I type. How do I fix this?


#2

Refresh the page and try again. If the input is still giving you trouble, a workaround would be to enter original manually and comment out the input line.


#3

Okay thank you, so there are no glaring problems with the code that I need to sort out?


#4

What you’re describing is that you have two variables.

One that you read input into, but otherwise ignore
And one that you never assign to, but use anyway

Restarting the python interpreter will result in that you get an error message when you try to read from the variable which you have not assigned anything to.


#5

I’m having a lot of trouble with this lesson too.
It keeps returning my else statement, which is strange b/c I choose solution and it still does it. So why is this happening?


#6

Ok now the only thing happening is being asked to enter a word.

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’


#7

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