+1 (315) 557-6473 

Program To Determine If The Characters Are a Part of The Hawaiian Alphabet in Python Assignment Solution.


Instructions

Objective
Write a python assignment to determine if the characters are a part of the Hawaiian alphabet.

Requirements and Specifications

Source Code
# Hawaiian Language Pronunciation Guide
# Alicia Lopez
# This is a program that determines if words are valid in the Hawaiian language;
# as well as providing how to pronounce the entered word.
# This function determines if the characters are a part of the Hawaiian alphabet.
def checkWord(word):
    characters = ['a', 'e', 'i', 'o', 'u', 'p', 'k', 'h', 'l', 'm', 'n', 'w', ' ', '\'']
    for c in word:
        if c not in characters:
            return False
    return True
# This function shows how to pronounce the given word.
def pronounceWord(word):
    pronounce = {}
    pronounce['p'] = "p"
    pronounce['k'] = "k"
    pronounce['h'] = "h"
    pronounce['l'] = "l"
    pronounce['m'] = "m"
    pronounce['n'] = "n"
    pronounce['p'] = "p"
    pronounce['a'] = "ah"
    pronounce['e'] = "eh"
    pronounce['i'] = "ee"
    pronounce['o'] = "oh"
    pronounce['u'] = "oo"
    pronounce['\''] = "\'"
    pronounce[' '] = " "
    result = []
    prev = None
    part = ""
    vowels = ['a', 'e', 'i', 'o', 'u']
    for c in word:
        if c == 'w':
            if prev is None or prev == 'a' or prev == 'o' or prev == 'u':
                part += "w"
            elif prev == 'i' or prev == 'e':
                part += "v"
        else:
            part += pronounce[c]
        if c in vowels:
            result.append(part)
            part = ""
        prev = c
    if len(part) > 0:
        result.append(part)
    return str.join("-", result)
# The main function that utilizes an interactive loop.
def main():
    while True:
        word = input("Enter a word to check if it is a valid Hawaiian word: ")
        if checkWord(word.lower()):
            print(word, "is a valid Hawaiian word and is pronounced as:")
            print(pronounceWord(word.lower()))
        else:
            print(word, "is a NOT valid Hawaiian word, please enter a VALID word to be pronounced")
        choice = input("Would you like to enter another word? Y/Yes or N/No? ")
        if choice[0].lower() == 'n':
            break
if __name__ == '__main__':
    main()