2014-10-31 67 views
0

我正在使用用戶輸入信函的ASL(美國手語)程序,並且作爲回報他們得到正確簽名的圖片。我可以一次處理一封信,但我希望得到完整的文字。 繼承人的循環IM工作:循環和顯示圖片的問題

from images import Image 
print('*** Welcome to the ASL Translator ***') 
print('Press ENTER to quit at any time') 
letter = input(str('What letter/word would you like to translate (A-Z): ')) 

#breaking the user input into letters 
seperate = list(letter) 

i = 0 
for i in range(len(seperate)): 
    if seperate[0] == 'A' or seperate[0] == 'a': 
     image = Image('A.gif') 
     image.draw() 
     i += 1 
    if seperate[1] == 'B' or seperate[1] =='b': 
     image = Image('B.gif') 
     image.draw() 
     i += 1 
    if seperate[2] == 'C' or seperate[2] == 'c': 
     image = Image('C.gif') 
     image.draw() 
     i += 1 

這是我有一次爲一個字母的作品。

if letter == 'A' or letter == 'a': 
    image = Image('A.gif') 
    image.draw() 
    i += 1 
elif letter == 'B' or letter == 'b': 
    image = Image('B.gif') 
    image.draw() 
    i+= 1 
elif letter == 'C' or letter == 'c': 
    image = Image('C.gif') 
    image.draw() 
    i+= 1 
elif letter == 'D' or letter == 'd': 
    image = Image('D.gif') 
    image.draw() 
elif letter == 'E' or letter == 'e': 
    image = Image('E.gif') 
    image.draw() 
elif letter == 'F' or letter == 'f': 
    image = Image('F.gif') 
    image.draw() 
elif letter == 'G' or letter == 'g': 
    image = Image('G.gif') 
    image.draw() 
elif letter == 'H' or letter == 'h': 
    image = Image('H.gif') 
    image.draw() 

。 。 。 。等到一切z

在此先感謝,如果你能幫助我! :)

回答

0
from images import Image 
print('*** Welcome to the ASL Translator ***') 
print('Press ENTER to quit at any time') 
letter = input(str('What letter/word would you like to translate (A-Z): ')) 


for ltr in letter.upper(): 
    if os.path.exists("%s.gif"%ltr): 
     image = Image("%s.gif"%ltr) 
     image.draw() 

我覺得應該工作

0

試試這個:

from images import Image 
print('*** Welcome to the ASL Translator ***') 
print('Press ENTER to quit at any time') 
letter = input(str('What letter/word would you like to translate (A-Z): ')) 

#breaking the user input into letters 
seperate = list(letter) 

for i in seperate: 
    i=i.upper() 
    image = Image(str(i)+'.gif') 
    image.draw() 
+0

完美!非常感謝你:) – 2014-10-31 22:36:34

+0

會有一種方法來顯示每個顯示器多個.gif圖片嗎?所以我可以一次寫完整個單詞而不是一個字母? @BHAT IRSHAD – 2014-10-31 22:42:39