Python String Help Hawaiian Word Pronunciation -
i having trouble figuring out why code not printing out after input value word. can input word, not output after evaluating through while loop. thoughts?
ai = "eye-" ae = "eye-" ao = "ow-" au = "ow-" ei = "ay-" eu = "eh-oo-" iu = "ew-" oi = "oy-" ou = "ow-" ui = "ooey-" = "ah-" e = "eh-" = "ee-" o = "oh-" u = "oo-" p = "p" k = "k" h = "h" l = "l" m = "m" n = "n" word = input("please enter hawaiian word want pronounced") character_count1 = int(0) character_count2 = int(1) pronunciation = "" while character_count1 < len(word): if word[character_count1:character_count2] == ai or word[character_count1:character_count2] == "ae"or word[character_count1:character_count2] == "ao"or word[character_count1:character_count2] == "ei"or word[character_count1:character_count2] == "eu"or word[character_count1:character_count2] == "iu"or word[character_count1:character_count2] == "oi"or word[character_count1:character_count2] == "ou": print("your word",pronunciation + word[character_count1:character_count2]) character_count1 + 2 , character_count2 + 2 elif word[character_count1:character_count1] == or word[character_count1:character_count1] == e or word[character_count1:character_count1] == or word[character_count1:character_count1] == o or word[character_count1:character_count1] == p or word[character_count1:character_count1] == k or word[character_count1:character_count1] == h or word[character_count1:character_count1] == l or word[character_count1:character_count1] == m or word[character_count1:character_count1] == n: print("your word",pronunciation + word[character_count1:character_count1] ) character_count1 + 1 , character_count2 + 1
what trying achieve pretty easy, if use data structure called dictionary, basic data structure in python. change data structure that:
dic={"ai" :"eye-","ae" :"eye-","ao": "ow-","au" :"ow-"......}
now can access values (pronunciation) keys (words).
like this,
dic["ai"]
you get:
eye-
so, let's try solution:
define dictionary.
dic={"ai" :"eye-","ae" :"eye-","ao": "ow-","au" :"ow-"......}
take input, better use raw_input if not using python3
word = raw_input("please enter hawaiian word want pronounced")
split input white spaces , form list.
lst=word.split()
use elements of lst
dictionary key
find value
. iterate through list , check if input matches key of dic
for in lst: print dic.get(i)
none
printed if key
doesn't exist.
as, requirement isn't quite clear me, have included things needed solve problem.
so, use them needed , solve problem.
happy coding.
Comments
Post a Comment