0

I have recently started learning how to program in Python using the site Codecademy.com, and it uses Python 2.7, and while I have installed both 2.7.3 and 3.3.2 on my computer I am creating the program in Python 3.

The program itself is a simple little proof of concept from the lessons on the site, a Pig Latin translator. I have decided to take it a step further and develop it to work on entire paragraphs of text, including spaces and other such instances, instead of only one word which is what the program originally did.

My problem at the moment is that the program is only outputting the same thing no matter what I put through, and I don't know why.

It only outputs the 'This isn't finished yet.' print of the code, which is for the instance of multiple words, obviously not done yet.

Here's the code:

pyg = 'ay'

raw_input = input('Enter your text here.  Numbers are not allowed. ')

if len(raw_input) > 0 and  raw_input.replace(' ', '').isalpha:
lower_input = raw_input.lower()

if lower_input[0] == " ":
    lower_input = lower_input[1:]

word_spacing = lower_input.replace(' ', '/')

if word_spacing.find('/'):
    print('This isn\'t finished yet.')

else:
    first_letter = raw_input[0]

    if first_letter == 'a' or 'e' or 'i' or 'o' or 'u':
        output = raw_input[1].upper() + raw_input[2:] + first_letter + pyg
        print(output)

    else:
        output = raw_input[0].upper() + raw_input[1:] + pyg
        print(output)

else:
print('The text you entered is invalid.')

end = input('Press Enter to exit')

If somebody could read over the code and help me debug this, that would be really helpful. Been staring at it for a while and still don't get it.

2 Answers 2

2

raw_input.replace(' ', '').isalpha

You didn't call the function isalpha, only referenced it. Add ()


if first_letter == 'a' or 'e' or 'i' or 'o' or 'u':

Is the same as:

if (first_letter == 'a') or ('e') or ('i') or ('o') or ('u'):

Which will always be True, as non-empty strings are considered True.

Change it to:

if first_letter in 'aeiou':


You also forgot to indent print('The text you entered is invalid.') at the bottom.

Sign up to request clarification or add additional context in comments.

1 Comment

Eh, formatting in here is weird, gotta get used to it. In my original code the indents are all correct, I'll try to check it better whenever I submit later. Thanks for the help.
0

That final else block lacks a matching if. Omit the last "else: " and its likely to work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.