printing and removing parts of a string

First, let me note that your initial if statement is flawed and always executes the if and never the else. So I changed it. I believe this is what you’re trying to do:

def main():
    word = input('Please enter a word ')
    if word[0] in "AEIOU":
        print(word + "hay")
        print(word[1].upper() + word[2:] + word[0].lower() + "ay")


This uses string slicing, where string[a:b] goes from string[a] up to but not including string[b], and when I leave out b it just goes to the end of the word.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top