# Arup Guha
# 11/10/2020
# Sample String Functions

# Return the number of times ch appears in word.
def countChar(word,ch):

    # Accumulator
    res = 0

    # Go to each character.
    for i in range(len(word)):

        # Only add 1 if this character is the one we are looking for.
        if word[i] == ch:
            res += 1

    return res

# returns True iff word is a palindrome, using negative indexing!
def isPal(word):

    # Go through half of the chars.
    for i in range(len(word)//2):

        # If the mirror characters are not equal, it is NOT a palindrome.
        if word[i] != word[-1-i]:
            return False

        # No else, if I had else return True, this would be wrong!!!

    # If we get here, we have a palindrome.
    return True

def convertToPigLatin(word):

    # Where is the first vowel?
    idx = indexFirstVowel(word)

    # No change since it has no vowel.
    if idx == -1:
        return word

    # Start vowel case.
    if idx == 0:
        return word + "way"

    # Start consonant case with vowel.
    return word[idx:]+word[:idx]+"ay"

# Return the non-neg index of the first vowel. If no vowel, -1 is returned.
def indexFirstVowel(word):

    # Try each index.
    for i in range(len(word)):

        # Check if it's a vowel if so return the correspnding index.
        if word[i] in "aeiouAEIOU":
            return i

    # If we get here there was no vowel.
    return -1

# Bunch of tests.
def tests():
    print(countChar("tennesee", "e"))
    print(countChar("tennesee", "n"))
    print(countChar("tennesee", "t"))
    print(countChar("tennesee", "p"))
    print(isPal("madamimadam"))
    print(isPal("tacocat"))
    print(isPal("tacoacat"))
    print(isPal("Z"))
    print(isPal("rr"))
    print(isPal("eW"))
    print(convertToPigLatin("shy"))
    print(convertToPigLatin("alluring"))
    print(convertToPigLatin("zebra"))

# Run it!
tests()
