我正在开展ASL(美国手语)计划,用户输入一封信,作为回报,他们会得到正确签名的照片。我可以一次用一个字母来处理它,但我希望得到完整的话。 继续我正在努力的循环:
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 :(得分: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()
我认为应该有效
答案 1 :(得分: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()